Android open source component SlidingMenu Side Slider menu introduction
- 2020-06-15 10:10:31
- OfStack
Many android apps now have side-slide menus that work well.
GitHub has the SlidingMenu open source library, which is easy to use.
SlidingMenu GitHub address: https: / / github com/jfeinstein10 / SlidingMenu. GitHub, Sliding ActionBarSherlock functions can be more abundant, ActionBarSherlock GitHub address: https: / / github com/JakeWharton/ActionBarSherlock
csdn download address:
SlidingMenu: http://download.csdn.net/detail/lanximu/7922377
ActionBarsherlock: http://download.csdn.net/detail/lanximu/7922383
Now, the use of SlidingMenu is described.
(1) Extract download zip from GitHub to local, and get one folder, library.
(2) Eclipse import Existing Code Into Workspace. Right-click on the project properties- > Android, as you can see, Is Library.
(3) Right click properties- on the project that will use SlidingMenu > Under Android, Library, enter the project add imported by (2).
(4) In order to ensure the success of the application of SlidingMenu library to the project, libs version 1 must be used by libs and SlidingMenu libraries used by the project, which mainly refers to ES71en-ES72en-v4.ES74en. If project libs does not exist or does not compile, try creating a new libs folder and placing android-ES78en-v4.jar. Right-click on libs - > Build Path- > Use as Source. It can be solved generally.
(5) After step (4), SlidingMenu can be used directly in the project.
Java code:
MainActivity:
package com.jj.testslidingmenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
public class MainActivity extends Activity {
SlidingMenu slidingMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
slidingMenu = new SlidingMenu(this);
slidingMenu.setMode(SlidingMenu.LEFT);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
slidingMenu.setMenu(R.layout.slidingmenu);
slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
}
@Override
public boolean onKeyDown(int key, KeyEvent event){
switch (key) {
case KeyEvent.KEYCODE_MENU:
slidingMenu.toggle(true);
break;
default:
break;
}
return false;
}
}
XMl layout code:
layout/slidingmenu.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff999999">
<com.jeremyfeinstein.slidingmenu.lib.SlidingMenu
android:id="@+id/slidingmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text = "click me"/>
</com.jeremyfeinstein.slidingmenu.lib.SlidingMenu>
</LinearLayout>
Some common property Settings for SlidingMenu are recorded as follows:
menu. setMode (SlidingMenu. LEFT); // Set the left slide menu
menu. setTouchModeAbove (SlidingMenu. TOUCHMODE_FULLSCREEN); // Set the range of the screen to slide, which can be set to the full screen area
menu. setShadowDrawable (R. drawable. shadow); // Set shadow image
menu. setShadowWidthRes (R. dimen. shadow_width); // Sets the width of the shadow image
menu. setBehindOffsetRes (R. dimen. slidingmenu_offset); //SlidingMenu underlining the remaining width shown on the main page
menu. setBehindWidth (400); // Set the width of the SlidingMenu menu
f menu. setFadeDegree (0.35); //SlidingMenu Slide gradient
menu. attachToActivity (this, SlidingMenu SLIDING_CONTENT); // Attach SlidingMenu to Activity
menu. setMenu (R. layout. menu_layout); // Set the layout file for menu
menu. toggle (); // Dynamic judgment automatically turns SlidingMenu off or on
menu. showMenu (); / / display SlidingMenu
menu. showContent (); // Display content
menu. setOnOpenListener (onOpenListener); // Listen for slidingmenu on
menu. setOnOpenedListener (onOpenedlistener); Listen for slidingmenu on
menu. OnCloseListener (OnClosedListener); // Listen for events when slidingmenu is closed
menu. OnClosedListener (OnClosedListener); // Listen for events after slidingmenu is closed
You can underline the SlidingMenu menu left and right just by setting it
menu. setMode (SlidingMenu. LEFT_RIGHT); Properties, and then sets the layout file for the right menu
menu. setSecondaryMenu (R. layout. menu_fram2); // Set the right menu
menu. setSecondaryShadowDrawable (R. drawable. shadowright); // Shadow image of the right menu