Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The getDecorView method return view include navigation bar view on lollipop?

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. my bottom view behind of navigation barmy bottom 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.

like image 301
Ray Avatar asked Nov 27 '14 07:11

Ray


People also ask

What is a navigationview?

Represents a standard navigation menu for application. The menu contents can be populated by a menu resource file. NavigationView is typically placed inside a DrawerLayout .

Where do I place the navigationview on the menu?

The menu contents can be populated by a menu resource file. NavigationView is typically placed inside a DrawerLayout .

Should I use the navigation state object in a release?

Note: Consider the navigator's state object to be internal and subject to change in a minor release. Avoid using properties from the navigation state object except index and routes, unless you really need it. If there is some functionality you cannot achieve without relying on the structure of the state object, please open an issue.

What is onnavigationitemselectedlistener in Android?

setNavigationItemSelectedListener ( NavigationView.OnNavigationItemSelectedListener listener) Set a listener that will be notified when a menu item is selected. Sets the drawable used for the inset foreground.


2 Answers

You could avoid this styling your activity like this:

<!-- 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" />
like image 61
Pedro Andrade Avatar answered Jan 02 '23 19:01

Pedro Andrade


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);
    } 
} 
like image 29
羅旭辰 Avatar answered Jan 02 '23 20:01

羅旭辰