Search code examples
androidactionbarsherlockback-buttonslidingmenu

How to implement SlidingMenu.OnOpenedListener correctly?


I want to hide back button when sliding menu is opened, otherwise to show it

How should I implement SlidingMenu OnOpenedListener?

I use this SlidingMenu with ActionBarSharlock.

enter image description here


Solution

  • Here is the solution, for those who are interested in.

    Set OnOpenedListener and OnClosedListener to your SlidingMenu object

    SlidingMenu menu = new SlidingMenu(this);
    
    • To show back button (sliding menu is closed)

      menu.setOnOpenedListener(new OnOpenedListener() {
      
                  @Override
                  public void onOpened() {
      
                      getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                  }
      
              });
      
    • To hide back button (sliding menu is opened)

      menu.setOnClosedListener(new OnOpenedListener() {
      
                  @Override
                  public void onClosed() {
      
                      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                  }
      
              });