gpt4 book ai didi

android - 在 Activity 中禁用 SlidingMenu

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:17:36 24 4
gpt4 key购买 nike

我有一个使用 SlidingMenu 的父类。子类扩展父类在单击主页图标时显示滑动菜单。

如何在子类中禁用滑动菜单?

代码父类:

 public class BCFragmentActivity extends SlidingFragmentActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setSlidingActionBarEnabled(true);

setBehindContentView(R.layout.slide_menu);

getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setShadowDrawable(R.drawable.shadow);
getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width);
getSlidingMenu().setBehindScrollScale(0.25f);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
}
return super.onOptionsItemSelected(item);
}

}

子类代码:

    public class SettingsPagerActivity extends BCFragmentActivity {

private ActionBar actionBar;
private ViewPager settingsPager;
private Tab profilesTab;
private Tab accountsTab;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_pager);


actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

settingsPager = (ViewPager) findViewById(R.id.settingsPage);
settingsPager.setOnPageChangeListener(pageChangeListener);

FragmentManager fm = getSupportFragmentManager();

profilesTab = actionBar.newTab()
.setText("Profile")
.setTabListener(tabListener);
accountsTab = actionBar.newTab()
.setText("Account")
.setTabListener(tabListener);

actionBar.addTab(profilesTab);
actionBar.addTab(accountsTab);

}

ActionBar.TabListener tabListener = new ActionBar.TabListener() {

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
settingsPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub

}

};

ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {

@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
actionBar.setSelectedNavigationItem(position);
}


};

}

最佳答案

我想不出“禁用”它的方法,但您可以通过调用子类来删除所有功能

getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);

这将为您的滑动菜单禁用任何手势检测。如果您有操作栏,请在 onCreate 中执行常规操作:

actionBar.setDisplayHomeAsUpEnabled(true);

并像没有 SlidingMenu 一样处理它:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

关于android - 在 Activity 中禁用 SlidingMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14109240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com