Recently developed Android app, the program used the toolbar control, want to set the toolbar Navigationicon icon but how to set the icon does not work, always show the control itself.
Abnormal:
Setting android:navigationicon= "@drawable/icon" in Layout XML or setting in code cannot be customized to Navigationicon pictures that you want to set.
The code settings are navigationicon as follows:
Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.my_toolbar);
Toolbar.setnavigationicon (R.drawable.icon);
Toolbar.settitle ("Title");
Toolbar.setsubtitle ("Sub");
Toolbar.setlogo (R.drawable.ic_launcher);
Setsupportactionbar (toolbar);
Solution:
If you set the toolbar setting Navigationicon in an XML layout, you now need to discard this practice, otherwise you will never be able to display the navigationicon you set;
You must use the Code method:
Setcontentview (r.layout.activity_main);
Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar);
Toolbar.settitle ("");
Toolbar.setsubtitle ("");
Setsupportactionbar (toolbar);
Drawerlayout drawer = (drawerlayout) Findviewbyid (r.id.drawer_layout);
Actionbardrawertoggle Toggle = new Actionbardrawertoggle (
This, drawer , toolbar, R.string.navigation_drawer_open, r.string.navigation_drawer_close);
Drawer.setdrawerlistener (toggle);
Toggle.syncstate ();
Toolbar.setnavigationicon (R.mipmap.userphoto);