Android toolbar setNavigationIcon not working

北城以北 提交于 2019-11-30 20:21:07

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);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!