我从SlideMenu的滑动菜单开始。我尝试了一个示例,效果很好,但是当显示菜单时,触摸右窗格或从左到右滑动会关闭滑动菜单。
我需要滑动菜单仅在从右到左滑动时关闭,或者可能在触摸时关闭。我不想从左向右滑动来关闭菜单。如何明确处理以上 3 种情况?
public class MainActivity extends SherlockFragmentActivity {
SlidingMenu menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(com.actionbarsherlock.R.style.Theme_Sherlock_Light);
setContentView(R.layout.activity_main);
menu = new SlidingMenu(this);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setMode(SlidingMenu.LEFT);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(200);
menu.setMenu(R.layout.menulayout);
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (item.getItemId() == android.R.id.home) {
menu.toggle();
}
return true;
}
}