目录:
1.概述
2.实现过程与代码
1.概述
在android开发中,咱们常常会有需求开发抽屉菜单,纵观当下的主流APP,大多首页都会有侧滑抽屉菜单,它的好处就在于,它能够
在有限的空间内显示尽可能多的控件。
抽屉菜单的实现方式也有不少种方式,下面我仅仅是经过官方的DrawerLayout+NavigationView+toolbar来实现与导航栏相关联的抽屉
菜单。
2.实现过程与代码
2.1 效果截图
由上面的效果图能够看出,其中的布局包括3部分,(1)主体布局,抽屉菜单未滑出时的显示布局 (2)抽屉菜单的头部布局 (3)抽屉菜单的菜单项布局
ok,下面会依次贴出上面的布局。
2.2 主布局文件activity_main.xml
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
/>
注:能够看出除了toolbar控件外,还导入了其drawerlayout_main布局,看看drawerlayout_main的布局以下
2.3 主布局文件中include包含文件drawerlayout_main.xml
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="matc