Advice: Implementation of SlidingMenu on Android (J. Feinstein)

后端 未结 3 660
轻奢々
轻奢々 2020-12-24 00:48

I have a problem (seriously, I do not know how to do it :D) with the implementation of SlidingMenu library (from Jeremy Feinstein... link is dowm) for Android. Is t

3条回答
  •  爱一瞬间的悲伤
    2020-12-24 01:25

    Create an Activity which extends SlidingActivity, create a Fragment for your menu and in the method onCreate add this :

    FrameLayout frameLayout = new FrameLayout(this);
    frameLayout.setId(ID_MENUFRAME);
    setBehindContentView(frameLayout);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    MenuFragment menuFragment = new MenuFragment();
    ft.replace(ID_MENUFRAME, menuFragment);
    ft.commit();
    

    where ID_MENUFRAME is an int which is not an id present in your layout (I set it to 1).
    Then, if you want to open or close the menu, call :

    getSlidingMenu().toggle();
    

    And you use your activity like any other activity.
    Note that you will have to customize your SlidingMenu programmatically. For example :

    sm.setBehindOffsetRes(R.dimen.slidingMenu_behindOffset);
    sm.setShadowWidthRes(R.dimen.slidingMenu_shadowWidth);
    sm.setShadowDrawable(R.drawable.slidingmenu_shadow);
    

提交回复
热议问题