简体   繁体   English

如何使SlidingMenu仅滑动内容而不是ActionBar

[英]How to make SlidingMenu only slide content and not the ActionBar

I am using SlidingMenu with ActionBarSherlock in my app and the way I have implemented it is by making a BaseActivity which extends SlidingFragmentActivity ( similar to the way they showed in the example ). 我使用SlidingMenu在我的应用程序ActionBarSherlock,我已经实现了它的方式是通过使BaseActivity延伸SlidingFragmentActivity (类似于他们在表现方式例子 )。 Every other activity in my app extends this BaseActivity. 我应用程序中的所有其他活动都扩展了此BaseActivity。

But currently, when I slide from the left in the App, the entire activity including the ActionBar slides. 但是目前,当我在App的左侧滑动时,包括ActionBar在内的整个活动都会滑动。 I only want the content to slide. 我只希望内容滑动。 So looking at the docs, I figured that adding this should do it: menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); 因此,看一下文档,我发现应该添加它: menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

But I get an error for that line - 但是我在那条线上遇到了错误-

java.lang.IllegalStateException: This SlidingMenu appears to already be attached

Here's the onCreate function of the BaseActivity - 这是BaseActivity的onCreate函数-

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(mTitleRes);

        // set the Behind View
        setBehindContentView(R.layout.menu_frame);
        if (savedInstanceState == null) {
            FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
            mFrag = new MenuListFragment();
            t.replace(R.id.menu_frame, mFrag);
            t.commit();
        } else {
            mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
        }

        // customize the SlidingMenu
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

   // **** This following line causes the error  *****
        sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

Should I be doing the attachToActivity somewhere else? 我应该在attachToActivity地方执行attachToActivity吗?

I eventually solved it by removing this from the Base activity - sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW); 我最终通过将其从基本活动中删除来解决了此问题sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);

and just adding this to the onCreate of all the inherited Activities: 并将其添加到所有继承的Activity的onCreate中:

setSlidingActionBarEnabled(false);

I guess this is coming from a long line of inheritance (myActivity --> BaseActivity ---> SlidingFragmentActivity --> SherlockFragmentActivity) 我猜这是从一长串继承而来的(myActivity-> BaseActivity ---> SlidingFragmentActivity-> SherlockFragmentActivity)

You used the command line: 您使用了命令行:

SlidingMenu sm = getSlidingMenu();

and you didn't attach the your menu because your menu is already attached. 并且您没有附加菜单,因为您的菜单已附加。

use the command: 使用命令:

sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW); 

if you create a new instance of SlidingMenu. 如果您创建一个新的SlidingMenu实例。 Like a SlidingMenu menu = new SlidingMenu(this); 就像一个SlidingMenu menu = new SlidingMenu(this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM