getDecorView方法返回视图包含棒棒糖上的导航栏视图?

ray*_*ray 10 android-activity slidingmenu android-5.0-lollipop

我使用SlidingMenu来实现我的滑入式菜单.

代码是

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);
}
Run Code Online (Sandbox Code Playgroud)

然后我遇到的问题是导航栏背后的布局. 我的导航栏后面的底部视图导航栏背后的底部布局

我将SlidingMenu.SLIDING_WINDOW更改为SlidingMenu.SLIDING_CONTENT.这是有效的,但动作栏总是在顶部.

看看SlidingMenu的源代码,我找到这个代码来添加slidemenu.

    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;
    }
Run Code Online (Sandbox Code Playgroud)

我该如何解决?这个bug只能在Android 5.0棒棒糖中找到.

sau*_*ito 22

您可以像这样避免这种样式的活动:

<!-- values-v21/styles.xml -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme" parent="FrameworkRoot.Theme">
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    </style>

</resources>


<!-- AndroidManifest.xml -->
<activity
        android:name="com.yourpackage.YourActivity"
        android:theme="Theme"
        android:screenOrientation="portrait" />
Run Code Online (Sandbox Code Playgroud)


小智 4

GitHub 上的 SlidingMenu 已经打开了同样的问题

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);
    } 
} 
Run Code Online (Sandbox Code Playgroud)