标签:
需要引入library(SlidingMenu以及ActionBarShelock)
1.MainActivity
package com.example.usingslidingmenu; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; public class MainActivity extends Activity { private SlidingMenu slidingMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); slidingMenu = new SlidingMenu(this); slidingMenu.setMode(SlidingMenu.LEFT_RIGHT); slidingMenu.setBehindOffsetRes(R.dimen.sliding_menu_offset); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); slidingMenu.setMenu(R.layout.slidingmenu); //设置右边的菜单 slidingMenu.setSecondaryMenu(R.layout.slidingmenu);//设置右侧菜单 slidingMenu.setSecondaryShadowDrawable(R.drawable.ic_launcher);//设置右侧菜单阴影的图片资源 } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: slidingMenu.toggle(true); break; default: break; } return super.onKeyDown(keyCode, event); } }
2.布局文件R.layout.slidingmenu
<?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:background="#ff999999" android:orientation="vertical" > <com.jeremyfeinstein.slidingmenu.lib.SlidingMenu android:id="@+id/slidingmenulayout" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="100dp" android:layout_height="30dp" android:text="click me"> </Button> </com.jeremyfeinstein.slidingmenu.lib.SlidingMenu> </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/piaocheng/p/4379551.html