Simple use of SlidingMenu
Directly run the Code:
MainActivity:
Package com. home. testslidingmenu; import android. OS. bundle; import android. support. v4.app. fragment; import android. view. view; import android. view. window; import com. home. textslidingmenu. r; import com. jeremyfeinstein. slidingmenu. lib. slidingMenu; import com. jeremyfeinstein. slidingmenu. lib. app. slidingFragmentActivity; public class MainActivity extends SlidingFragmentActivity {@ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. main); initSlidingMenu ();}/*** initialize SlidingMenu */private void initSlidingMenu () {Fragment leftMenuFragment = new LeftFragment (); setBehindContentView (R. layout. left_menu_frame); getSupportFragmentManager (). beginTransaction (). replace (R. id. left_menu_frame_rootlayout, leftMenuFragment ). commit (); SlidingMenu menu = getSlidingMenu (); // slide menu on the left and right sides. setMode (SlidingMenu. LEFT_RIGHT); // Slide left // menu. setMode (SlidingMenu. LEFT); // slide to the right // menu. setMode (SlidingMenu. RIGHT); // set the touch screen mode: click menu at the corner. setTouchModeAbove (sregistringmenu. TOUCHMODE_MARGIN); // sets the touch screen mode: full screen touch menu. setTouchModeAbove (sregistringmenu. TOUCHMODE_FULLSCREEN); // sets the shadow width menu. setShadowWidthRes (R. dimen. shadow_width); // sets the shadow effect menu. setShadowDrawable (R. drawable. shadow); // set the width of the sliding menu view. setBehindOffsetRes (R. dimen. slidingmenu_offset); // menu. setBehindWidth (0); // set the value of the gradient effect menu. setFadeDegree (0.35f); // menu. setBehindScrollScale (1.0f); // set the menu shadow effect on the right. setSecondaryShadowDrawable (R. drawable. shadow); // set the right (level 2) slide menu. setSecondaryMenu (R. layout. right_menu_frame); Fragment rightMenuFragment = new RightFragment (); getsuppfrfragmentmanager (). beginTransaction (). replace (R. id. right_menu_frame_rootlayout, rightMenuFragment ). commit ();} public void showLeftMenu (View view) {getSlidingMenu (). showMenu ();} public void showRightMenu (View view) {getSlidingMenu (). showSecondaryMenu ();}}LeftFragment:
package com.home.testslidingmenu;import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import com.home.textslidingmenu.R;public class LeftFragment extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {return inflater.inflate(R.layout.left_menu, container, false);}}RightFragment:
package com.home.testslidingmenu;import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import com.home.textslidingmenu.R;public class RightFragment extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {return inflater.inflate(R.layout.left_menu, container, false);}}
Left_selector.xml in drawable:
Right_selector.xml in drawable:
Shadow. xml in drawable:
Layout file:
Main. xml:
Left_menu.xml:
Right_menu.xml:
Left_menu_frame.xml:
<framelayout android:id="@+id/left_menu_frame_rootlayout" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"></framelayout>
Right_menu_frame.xml:
<framelayout android:id="@+id/right_menu_frame_rootlayout" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"></framelayout>
Dimens. xml:
16dp
16dp
60dp
5dp