NavigationView的使用

代码已经分享至github:https://github.com/YanYoJun/NavigationDemo

转载请注明原文链接:http://www.cnblogs.com/yanyojun/p/8076015.html

一、直接看布局

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:id="@+id/drawer_layout"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     android:fitsSystemWindows="true"
 9     tools:openDrawer="start">
10 
11     <include
12         layout="@layout/app_bar_main"
13         android:layout_width="match_parent"
14         android:layout_height="match_parent" />
15 
16     <android.support.design.widget.NavigationView
17         android:id="@+id/nav_view"
18         android:layout_width="wrap_content"
19         android:layout_height="match_parent"
20         android:layout_gravity="start"
21         android:fitsSystemWindows="true"
22         app:headerLayout="@layout/nav_header_main"
23         app:menu="@menu/activity_main_drawer" />
24 
25 </android.support.v4.widget.DrawerLayout>

额,其实就这么点东西,其他也没有什么,在DrawerLayout中嵌套一个NavigationView就可以了

这里有一个fitSystemWindow,这句话总结的很好:

fitsSystemWindow 默认是true,就是组件都在屏幕内,但是不包括statusBar。设置成false后,整个屏幕都可以放置组件,没有statusBar和window之分。

原文地址:https://www.cnblogs.com/yanyojun/p/8076015.html