Pergunta

I am using Jeremy Feinstein's sliding menu for Android, and I need help running a method when the SlidingMenu opens and/or closes. I'd like to change an icon depending on the state of the menu. I tried subclassing SlidingMenu and overwriting the toggle method, like so:

public class SlidingMenuCustom extends SlidingMenu {

ImageView plus;

public SlidingMenuCustom(Activity activity, ImageView plus) {
    super(activity);
    this.plus = plus;
}

@Override
public void toggle(){
    super.toggle();
    Log.d("Hello", Global.debug + " " + isMenuShowing());
    if(isMenuShowing()){
        plus.setImageResource(R.drawable.sidenavminus);
    }else{
        plus.setImageResource(R.drawable.sidenavplus);
    }


}

}

But then I realized that toggle is only ever called if I call it, so that wouldn't work. Is there something else that I can do to run a method when the sliding menu opens or closes?

Foi útil?

Solução

jfeinstein10 sliding menu provide listnere when sliding menu open and close

Override below method to your class

1.Open sliding menu listener

     slidingmenu.setOnOpenedListener(new OnOpenedListener() {

        @Override
        public void onOpened() {
               //execute your code
        }

    });

1.Close sliding menu listener

     slidingmenu.setOnClosedListener(new OnOpenedListener() {

        @Override
        public void onClosed() {
               //execute your code
         }

    });
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top