I have activity with DrawerLayout . I can open the box in two different ways ... by scrolling the left side of the screen to the right and clicking on the application title. I do NOT see the application icon, only the title. I implemented it exactly as Google recommended here: Creating a navigation box: open and close using the application icon
Everything works functionally, opening and closing the box itself. However, it does not display the standard DrawerLayout icon that is intended to be used. Instead, I get the usual caret (it looks like a smaller sign).
As soon as I add the application icon back to the ActionBar , it will start working as expected. The drawer layout icon displays and enlivens when the drawer is open or closed. I tried to remove the application icon both in the XML stylesheet and programmatically.
Is there a way to get the DrawerLayout icon without the application icon ???
UPDATE: I found a job, but this hack is more than a solution. I just created a transparent 1x1 pixel PNG (blank.png) and set it as my application icon in the styles.xml file. Below is all the relative code:
styles.xml
<style name="MyCustomTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:actionBarStyle">@style/MyCustomActionBar</item> <item name="android:icon">@drawable/blank</item> </style> <style name="MyCustomActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:displayOptions">showHome|showTitle|homeAsUp</item> </style>
MainActivity → onCreate ()
this.navDrawerToggle = new ActionBarDrawerToggle ( this, this.navDrawerLayout, R.drawable.icon_nav_drawer, R.string.nav_drawer_open, R.string.nav_drawer_closed ) { public void onDrawerClosed(View view) {} public void onDrawerOpened(View drawerView) {} };
MainActivity → onPostCreate ()
super.onPostCreate(savedInstanceState); this.navDrawerToggle.syncState();
MainActivity → onResume ()
this.navDrawer.setOnItemClickListener(new DrawerItemClickListener()); this.navDrawerLayout.setDrawerListener(this.navDrawerToggle);
MainActivity → onPause ()
this.navDrawer.setOnItemClickListener(null); this.navDrawerLayout.setDrawerListener(null);
MainActivity → onConfigurationChanged (Configuration newConfig)
super.onConfigurationChanged(newConfig); navDrawerToggle.onConfigurationChanged(newConfig);
MainActivity → onOptionsItemSelected (MenuItem element)
if (this.navDrawerToggle.onOptionsItemSelected(item)) {return true;} else { // A bunch of item click handling happens here... return true; }