Toolbar back button is not calling onOptionsItemSelected Android

微笑、不失礼 提交于 2019-11-29 18:24:44

If you want the onOptionsItemSelected() method to fire when the toggle Button is clicked, you need to use the four-parameter constructor for ActionBarDrawerToggle that doesn't take a Toolbar argument.

public ActionBarDrawerToggle(Activity activity,
                             DrawerLayout drawerLayout,
                             int openDrawerContentDescRes,
                             int closeDrawerContentDescRes)

Otherwise, the toggle will just handle the drawer opening/closing directly itself.

Sai Kiran

And i finally got a solution. instead getting toolbar home button click ononOptionsItemSelected() it can be handled through DrawerToggle.setToolbarNavigationClickListener.

mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // event when click home button
                Log.d("cek", "home selected");
            }
        });

Thanks to @meow meo. Source - Cannot catch toolbar home button click event

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