So, I have a BaseActivity in which I have a toolbar and I call setSupportActionBar(toolbar).
In some of my activities that extends BaseActivity, I would like to change the navigation icon (the default arrow) to another drawable. But when I call toolbar.setNavigationIcon(myDrawable) it doesn't work, it still shows the default left pointing arrow icon.
Any idea? Thanks.
I think you can set like this
menuDrawerToggle = new ActionBarDrawerToggle(this, menuDrawer, toolbar, R.string.drawer_open, R.string.drawer_close){...}
menuDrawerToggle.syncState();
toolbar.setNavigationIcon(getResources().getDrawable(yourDrawable));
put setNavigationIcon after syncState()
In my case: I don`t use ActionBarDrawerToggle. For me helpful was: to change order of methods calls.
From:
Toolbar toolbar = (Toolbar)getActivity().findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_chevron_left_white_24dp);
To:
Toolbar toolbar = (Toolbar)getActivity().findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_chevron_left_white_24dp);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
In my case, setNavigationIcon after syncState as @Hsieh not work! My solution is set in onPostCreate method as below. Override this method in your activity
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mToolbar.setNavigationIcon(R.drawable.ic_menu_button);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With