Disable SlidingMenu in activity
Asked Answered
V

2

7

I have one parent class which uses SlidingMenu. And the childs extending parent class shows the sliding menu on Home Icon click.

How to disable the sliding menu in the child classes?

codes Parent Class :

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

}

codes for child Class :

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


    };      

}
Vagabond answered 1/1, 2013 at 9:16 Comment(1)
Was this ever resolved?Knurl
D
14

I can't think of a way to "disable" it, but you can remove all of the functionality by calling in the child class

getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);

This will disable any gesture detection for your sliding menu. If you have an action bar, do the usual in onCreate:

actionBar.setDisplayHomeAsUpEnabled(true);

and handle it as if you don't have a SlidingMenu:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Dinnerware answered 10/5, 2013 at 6:29 Comment(1)
that did the trick! To re-enable I use SlidingMenu.TOUCHMODE_MARGINKellen
U
0

Try overriding onBackPressed() in your child activity.

@Override
public void onBackPressed() {
this.finish();
overridePendingTransition(0, 0);
}
Unbreathed answered 1/1, 2013 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.