该getDecorView方法返回查看包括棒棒糖导航栏的看法?棒棒糖、看法、方法、getDecorView

2023-09-12 05:24:53 作者:爱情,我戒了

我使用 SlidingMenu 实现我的滑盖式菜单。

在code是

 私人无效initSlidingMenu()
{
    //配置SlidingMenu
    菜单=新SlidingMenu(本);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    // menu.setShadowDrawable(R.drawable.shadoew);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    // menu.setFadeDegree(0.35f);
    menu.attachToActivity(这一点,SlidingMenu.SLIDING_WINDOW);
    menu.setMenu(R.layout.menu_main_sliding);
}
 

后来我有一个问题,就是我的导航栏后面的布局。

和我改变SlidingMenu.SLIDING_WINDOW到Sli​​dingMenu.SLIDING_CONTENT。 它的作品,但始终在顶部的动作条。

看SlidingMenu源$ C ​​$ C,我觉得这是code添加slidingmenu。

 开关(slideStyle){
    案例SLIDING_WINDOW:
        mActionbarOverlay = FALSE;
        ViewGroup中的装饰=(ViewGroup中)activity.getWindow()getDecorView()。
        ViewGroup中decorChild =(ViewGroup中)decor.getChildAt(0);
        //保存动作条的主题,有透明的资产
        decorChild.setBackgroundResource(背景);
        decor.removeView(decorChild);
        decor.addView(本);
        setContent(decorChild);
        打破;
    案例SLIDING_CONTENT:
        mActionbarOverlay = actionbarOverlay;
        //把上述观点出
        ViewGroup中contentParent =(ViewGroup中)activity.findViewById(android.R.id.content);
        查看内容= contentParent.getChildAt(0);
        contentParent.removeView(内容);
        contentParent.addView(本);
        setContent(内容);
        //救人具有透明背景
        如果(content.getBackground()== NULL)
            content.setBackgroundResource(背景);
        打破;
    }
 
选一块糖果测一测你会黑化成多坏 我居然黑到亲妈都不认识

我该如何解决呢? 这一问题只在安卓5.0棒棒糖找到。

解决方案

SlidingMenu在GitHub上开设了相同的问题。

 私人诠释getNavigationBarHeight(){
    资源资源= getResources();
    INT RESOURCEID = resources.getIdentifier(navigation_bar_height,地扪,机器人);
    如果(RESOURCEID大于0){
        返回resources.getDimensionPixelSize(RESOURCEID);
    }
    返回0;
}

@覆盖
公共无效的onCreate(包savedInstanceState){
    如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.LOLLIPOP){
        INT navBarHeight = getNavigationBarHeight();
        findViewById(R.id.base_frame).setPadding(0,0,0,navBarHeight);
        findViewById(R.id.menu_frame).setPadding(0,0,0,navBarHeight);
    }
}
 

I use SlidingMenu to implement my slide-in menus.

The code is

private void initSlidingMenu()
{
    // configure the SlidingMenu
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    //        menu.setShadowDrawable(R.drawable.shadoew);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    //        menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
    menu.setMenu(R.layout.menu_main_sliding);
}

Then I got a problem is my layout behind of navigation bar.

And i change the SlidingMenu.SLIDING_WINDOW to SlidingMenu.SLIDING_CONTENT. It's works,but the actionbar always on the top.

Look at the source code of SlidingMenu,i find this code to add slidingmenu.

    switch (slideStyle) {
    case SLIDING_WINDOW:
        mActionbarOverlay = false;
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        // save ActionBar themes that have transparent assets
        decorChild.setBackgroundResource(background);
        decor.removeView(decorChild);
        decor.addView(this);
        setContent(decorChild);
        break;
    case SLIDING_CONTENT:
        mActionbarOverlay = actionbarOverlay;
        // take the above view out of
        ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content);
        View content = contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this);
        setContent(content);
        // save people from having transparent backgrounds
        if (content.getBackground() == null)
            content.setBackgroundResource(background);
        break;
    }

How can i fix it? This bug only found in Android 5.0 lollipop.

解决方案

SlidingMenu on GitHub has opened same issue.

private int getNavigationBarHeight() { 
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    } 
    return 0; 
} 

@Override 
public void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int navBarHeight = getNavigationBarHeight();
        findViewById(R.id.base_frame).setPadding(0, 0, 0, navBarHeight);
        findViewById(R.id.menu_frame).setPadding(0, 0, 0, navBarHeight);
    } 
}