Android Navigation Drawer Icon reverting to default when Drawer is open -


i'm having problem navigation drawer icon.
replaced default "back caret" use different icon , works fine.

however, if navigation drawer open , user rotates device, icon reverts default caret , won't go custom 1 until navigation drawer closed , oncreate() method activity called again (usually rotating device).

here code:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_start);      // set toolbar action bar     toolbar toolbar = (toolbar) findviewbyid(r.id.my_awesome_toolbar);     toolbar.setnavigationicon(r.drawable.ic_drawer);     setsupportactionbar(toolbar);      if (savedinstancestate == null) {         getsupportfragmentmanager().begintransaction()                 .add(r.id.container, new startfragment())                 .commit();     }      //init gamelog     gamelog.init(this); }  /**  * initializes drawerlayout particular activity  */ public static void init(activity activity) {     mactivity = activity;     mdrawerlayout = (drawerlayout)activity.findviewbyid(r.id.drawer_layout);     mrecyclerview = (recyclerview)activity.findviewbyid(r.id.left_drawer);      //set adapter     mrecyclerview.setadapter(madapter);     //set layout manager     mrecyclerview.setlayoutmanager(new linearlayoutmanager(activity, linearlayoutmanager.vertical, false));     //add divider between elements     mrecyclerview.additemdecoration(             new horizontaldivideritemdecoration.builder(activity)                     .color(color.white)                     .build());      toolbar toolbar = (toolbar)((actionbaractivity)activity).getsupportactionbar().getcustomview();      mdrawertoggle = new actionbardrawertoggle(activity, mdrawerlayout, toolbar, r.string.drawer_open, r.string.drawer_close);      // set drawer toggle drawerlistener     mdrawerlayout.setdrawerlistener(mdrawertoggle);      if (activity.getactionbar() != null) {         activity.getactionbar().setdisplayhomeasupenabled(true);         activity.getactionbar().sethomebuttonenabled(true);     }  }  @override protected void onpostcreate(bundle savedinstancestate) {     super.onpostcreate(savedinstancestate);     // sync toggle state after onrestoreinstancestate has occurred.     gamelog.gettoggle().syncstate(); } 

hopefully makes sense.

thanks help.

look calling actionbardrawertoggle#syncstate.

https://developer.android.com/reference/android/support/v4/app/actionbardrawertoggle.html#syncstate()


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -