效果演示
演示
NavigationView的布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/navigation_background_light"
android:overScrollMode="never"
app:headerLayout="@layout/layout_navigation_header"
app:menu="@menu/navigation_main" />
</android.support.v4.widget.DrawerLayout>
下面才是关键
1、app:headerLayout="@layout/layout_navigation_header"
这条代码的作用就是设置导航抽屉的样子
layout_navigation_header布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/header_container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
android:clickable="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<ImageView
android:id="@+id/background_image_view"
android:layout_width="wrap_content"
andr