简体   繁体   English

如何使用SlidingMenu库

[英]How to work with SlidingMenu library

I am using the [SlidingMenu][1] Library in my App and have made a menu but I am not sure how to customize this. 我在我的应用程序中使用[SlidingMenu] [1]库,并创建了一个菜单,但不确定如何自定义。

First, the Up Navigation button on the action bar does not pull up the menu. 首先,操作栏上的“向上导航”按钮不会拉起菜单。 It just does not do anything when clicked. 单击时它什么都不做。 The menu works by sliding in anywhere on the screen but not with that button. 菜单可通过在屏幕上的任意位置滑动而不使用该按钮来工作。

Also, is there a way to change that up navigation '<' icon and make it work like Google + or others with the animation of the three horizontal lines? 另外,有没有办法更改向上导航“ <”图标,并使它与Google+或其他带有水平三条线的动画一起工作?

My code is as follows: 我的代码如下:

public class BaseActivity extends SlidingFragmentActivity {

    private int mTitleRes;
    protected ListFragment mFrag;

    public BaseActivity(int titleRes) {
        mTitleRes = titleRes;
    }

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

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    }

}

And the main activity: 和主要活动:

public class StatusActivity extends BaseActivity {

    public StatusActivity() {
        super(R.string.title_status_page);
    }


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

        setSlidingActionBarEnabled(false);
..
..

Try this: 尝试这个:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        getSlidingMenu().showContent();
    }
    return false;
}

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

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