Cannot catch toolbar home button click event

前端 未结 11 1987
悲&欢浪女
悲&欢浪女 2020-11-27 02:56

I\'ve implemented the newest appcompat library and using the Toolbar as action bar. But the problem is I cannot catch the home button / hamburger icon click eve

11条回答
  •  -上瘾入骨i
    2020-11-27 03:18

    In my case I had to put the icon using:

    toolbar.setNavigationIcon(R.drawable.ic_my_home);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    

    And then listen to click events with default onOptionsItemSelected and android.R.id.home id

提交回复
热议问题