简体   繁体   中英

Drawer toggle button not displaying on Action Bar

I have two activities in my app and both have navigation drawers implemented. Now the scenario is that the Drawer toggle is getting displayed for the first activity but for the same code its not getting displayed for the second activity (which is getting called from the first activity). I don't have much experience in Android Programming and I am stuck on this one. Please help anyone :(

Here's the Java Code snippet to display drawer toggle button:

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout_quiz);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

在此处输入图片说明

您必须先获取工具栏,然后设置支持操作栏

setSupportActionBar(toolbar);

Ok after struggling for 2 days I finally found what the problem was. drum rolls please ....

The problem was : Z INDEX OF THE CUSTOM ACTION BAR LAYOUT INSIDE DRAWER LAYOUT .

You heard it .. if you are facing similar issues like for example your custom action bar layout is not displaying or your drawer toggle button is not displaying the first thing you should check if your action bar layout is placed down below all your main layouts to increase its z order.

In my case I placed it above my main layouts in the drawer layout. And the funny thing is Android Studio's preview window was still displaying the custom action bar as if it doesn't even care about the z index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM