Cannot catch toolbar home button click event

前端 未结 11 2012
悲&欢浪女
悲&欢浪女 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条回答
  •  悲哀的现实
    2020-11-27 03:13

    The easiest approach we could do is change the home icon to a known icon and compare drawables (because android.R.id.home icon can differ to different api versions

    so set a toolbar as actionbar SetSupportActionBar(_toolbar);

    _toolbar.NavigationIcon = your_known_drawable_here;
    
       for (int i = 0; i < _toolbar.ChildCount; i++)
                {
                    View v = _toolbar.GetChildAt(i);
                    if (v is ImageButton)
                    {
                        ImageButton imageButton = v as ImageButton;
    
                        if (imageButton.Drawable.GetConstantState().Equals(_bookMarkIcon.GetConstantState()))
                        {
                           //here v is the widget that contains the home  icon you can add your click events here 
                        }
                    }
                }
    

提交回复
热议问题