GoogleNavigationDrawerMenu-侧滑menu菜单.zip
DrawerLayout的封装,对于菜单是ListView的应用来说,这个库提供了更直接的使用方式,你不再需要去写menu的布局,如果你对DrawerLayout的使用没有信心,这个库使用起来可能会让你觉得简单些。项目地址:https://github.com/Arasthel/GoogleNavigationDrawerMenu效果图:如何使用方法1. 直接用java代码创建 1. 首先你需要创建个内容页的布局文件<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.dexafree.googlenavigationdrawermenusample.MainActivity"> <TextView android:text="Hello world!" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> 2. 创建菜单实例 mDrawer = new GoogleNavigationDrawer(this); mDrawer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 3. 创建菜单项 mDrawer.setListViewSections(new String[]{"Section A", "Section B", "Section C"}, // Main sections new String[]{"Settings01", "Settings02"}, // Secondary sections new int[]{R.drawable.ic_launcher}, // Main sections icon ids null); 4. 设置内容页LayoutInflater inflater = getLayoutInflater(); View contentView = inflater.inflate(R.layout.main_content, null); mDrawer.addView(contentView, 0); 5. 设置选择监听器mDrawer.setOnNavigationSectionSelected(new GoogleNavigationDrawer.OnNavigationSectionSelected() { @Override public void onSectionSelected(View v, int i, long l) { Toast.makeText(getBaseContext(), "Selected section: " i, Toast.LENGTH_SHORT).show(); } }); 6. 最后将菜单附加到页面上setContentView(mDrawer); 方法2. 在xml中创建菜单实例及内容页<org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer xmlns:android="http://schemas.android.com/apk/res/android"xmlns:drawer="http://schemas.android.com/apk/res-auto"android:id="@ id/navigation_drawer_container"android:layout_width="match_parent"android:layout_height="match_parent"drawer:list_paddingTop="?android:actionBarSize"drawer:drawer_gravity="start"drawer:list_mainSectionsEntries="@array/navigation_main_sections"drawer:list_secondarySectionsEntries="@array/navigation_secondary_sections"drawer:list_mainSectionsDrawables="@array/drawable_ids"drawer:list_secondarySectionsDrawables="@array/drawable_ids"> <FrameLayout android:id="@ id/content_layout" android:layout_width="match_parent" android:layout_height="match_parent"/> </org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer> 接下来就按照方法1的步骤3、步骤5.
- 1
- 2
- 粉丝: 694
- 资源: 4万+
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助