码迷,mamicode.com
首页 > 移动开发 > 详细

Android开发-SlidingMenu

时间:2015-03-31 00:31:35      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

需要引入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>

 

Android开发-SlidingMenu

标签:

原文地址:http://www.cnblogs.com/piaocheng/p/4379551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!