android – 在活动中禁用SlidingMenu

前端之家收集整理的这篇文章主要介绍了android – 在活动中禁用SlidingMenu前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用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);
    }
}
原文链接:https://www.f2er.com/android/317080.html

猜你在找的Android相关文章