2014-02-19 58 views
0

我正在使用Jeremy Feinstein的滑動菜單進行Android操作,並且在SlidingMenu打開和/或關閉時需要幫助運行方法。我想根據菜單的狀態更改圖標。我試着子類SlidingMenu和覆蓋切換方法,像這樣:SlidingMenu打開或關閉時的運行方法

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


} 

} 

但後來我意識到,切換隻會被調用,如果我把它,這樣是行不通的。當滑動菜單打開或關閉時,我還能做些什麼來運行方法嗎?

回答

6

jfeinstein10滑動菜單滑動菜單打開和關閉

Override below method to your class 

1.Open滑動菜單聽衆

 slidingmenu.setOnOpenedListener(new OnOpenedListener() { 

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

    }); 

1.關閉滑動菜單偵聽器時提供listnere

 slidingmenu.setOnClosedListener(new OnOpenedListener() { 

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

    }); 
+0

但如何區分主菜單和二級菜單? –