SlidingMenu打开或关闭时的运行方法

时间:2014-02-19 17:05:15

标签: android slidingmenu

我正在使用Jeremy Feinstein的Android滑动菜单,当SlidingMenu打开和/或关闭时,我需要帮助运行方法。我想根据菜单的状态更改图标。我尝试了子类化SlidingMenu并覆盖toggle方法,如下所示:

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);
    }


}

}

但后来我意识到只有在我调用它时才会调用切换,这样就行不通了。当滑动菜单打开或关闭时,我还能做些什么来运行方法吗?

1 个答案:

答案 0 :(得分:6)

  当滑动菜单打开时,jfeinstein10滑动菜单提供listnere   靠近

Override below method to your class

1.打开滑动菜单监听器

     slidingmenu.setOnOpenedListener(new OnOpenedListener() {

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

    });

1.关闭滑动菜单监听器

     slidingmenu.setOnClosedListener(new OnOpenedListener() {

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

    });