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之分。

posted @   程小白  阅读(585)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示