Change drawer icon back to back arrow

后端 未结 2 1862
长发绾君心
长发绾君心 2020-12-23 11:33

I\'m using the new DrawerLayout to have side navigation. I\'m using the drawer icon (the \'hamburger\') like this:

@Override
protected void onSt         


        
相关标签:
2条回答
  • 2020-12-23 12:03

    To disable and hide the DrawerToggle "Hamburger", just call

    mDrawerToggle.setDrawerIndicatorEnabled(false);
    
    0 讨论(0)
  • 2020-12-23 12:04

    I created an interface for the hosting activity to update the view state of the hamburger menu. For top level fragments I set the toggle to true and for fragments for which I want to display the up < arrow I set the toggle to false.

    public class SomeFragment extends Fragment {
    
        public interface OnFragmentInteractionListener {
            public void showDrawerToggle(boolean showDrawerToggle);
        }
    
        private OnFragmentInteractionListener mListener;
    
        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            try {
                this.mListener = (OnFragmentInteractionListener) activity;
            } catch (ClassCastException e) {
                throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
            }
        }
    
        @Override
        public void onResume() {
            super.onResume();
            mListener.showDrawerToggle(false);
        }
    }
    

    Then in my Activity ...

    public class MainActivity extends Activity implements SomeFragment.OnFragmentInteractionListener {
    
        private ActionBarDrawerToggle mDrawerToggle;
    
        public void showDrawerToggle(boolean showDrawerIndicator) {
            mDrawerToggle.setDrawerIndicatorEnabled(showDrawerIndicator);
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题