android29之UI控件的抽屉式实现方法之一(DrawerLayout和NavigationView)
添加依赖
implementation 'com.google.android.material:material:1.2.0-alpha06'
在Layout中创建两个Xml布局文件,header.xml和menu.xml
header.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#F89215"
/>
</LinearLayout>
menu.xml文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<group android:checkableBehavior="single">
<item android:title="首页" />
<item android:title="收藏" />
<item android:title="设置" />
<item android:title="关于" />
<item android:title="分享" />
</group>
</menu>
activity_main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#5EA7F3"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.navigation.NavigationView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@layout/nav_menu"
/>
</androidx.drawerlayout.widget.DrawerLayout>
运行结果如下

android29之UI控件的抽屉式实现方法之一(DrawerLayout和NavigationView)的更多相关文章
- 实现跨线程访问UI控件的3种方法
namespace 多线程 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } privat ...
- Qt常用UI控件读取、写入方法
本文用途:快速备忘,方便调用,写熟了自然就记下了. [1.标签label] 读取:ui->label->text() 写入:ui->label->setText("p ...
- C#子线程更新UI控件的方法总结
http://blog.csdn.net/jqncc/article/details/16342121 在winform C/S程序中经常会在子线程中更新控件的情况,桌面程序UI线程是主线程,当试图从 ...
- C# Winform 跨线程更新UI控件常用方法汇总(多线程访问UI控件)
概述 C#Winform编程中,跨线程直接更新UI控件的做法是不正确的,会时常出现“线程间操作无效: 从不是创建控件的线程访问它”的异常.处理跨线程更新Winform UI控件常用的方法有4种:1. ...
- C# Winform 跨线程更新UI控件常用方法总结(转)
出处:http://www.tuicool.com/articles/FNzURb 概述 C#Winform编程中,跨线程直接更新UI控件的做法是不正确的,会时常出现“线程间操作无效: 从不是创建控件 ...
- ANDROID L——Material Design详解(UI控件)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
- WinForm/Silverlight多线程编程中如何更新UI控件的值
单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...
- 富客户端 wpf, Winform 多线程更新UI控件
前言 在富客户端的app中,如果在主线程中运行一些长时间的任务,那么应用程序的UI就不能正常相应.因为主线程要负责消息循环,相应鼠标等事件还有展现UI. 因此我们可以开启一个线程来格外处理需要长时间的 ...
- UI控件(复习一下)
如何修改控件状态• 可见,确实需要经常修改控件状态• 那如何去修改控件的状态呢?方法很简单➢ 每一个UI控件都是一个对象➢ 修改UI控件的状态,其实就是修改控件对象的属性➢ 比如修改UILabel显示 ...
随机推荐
- LeetCode--179场周赛题解
水题: class Solution { public: string generateTheString(int n) { string s; string a="a",b=&q ...
- VMware 虚拟机正在使用中
1.出现报错信息: 2.找到安装目录下面的.lck后缀文件夹(如有多个则全部删除) 3.删除此文件夹 4.成功开启虚拟机
- jsp(3,6,9) EL表达式及JSTL
1. jsp 1.1jsp是什么 全称: Java Server Pages,java服务器页面.和Servlet一样,是sun公司定义的一种动态网页开发技术. 特点:基于html模版,可以在h ...
- sql 语句系列(字符串的遍历嵌入删除与统计)[八百章之第十一章]
遍历字符串 我觉得首先要提出一个疑问: 一个数据库本身就是用于存储的,遍历字符串究竟有何意义? 先看如何实现的,毕竟sql service 是没有for循环,也没有loop和while的. selec ...
- Django之CBV装饰器,跨站请求伪造,auth认证
CBV加装饰器 基于session实现登录 def login(request): if request.method == 'POST': username = request.POST.get(' ...
- 设计模式 - 观察者模式 (C++实现)
#include <iostream> #include <list> #include <string> using namespace std; class I ...
- 原来 CPU 为程序性能优化做了这么多
本文主要来学习内存屏障和 CPU 缓存知识,以便于我们去了解 CPU 对程序性能优化做了哪些努力. 首先来看下 CPU 缓存: CPU 缓存 CPU 缓存是为了提高程序运行的性能,CPU 在很多处理上 ...
- springboot2 + mybatis 多种方式实现多数据配置
业务系统复杂程度增加,为了解决数据库I/O瓶颈,很自然会进行拆库拆表分服务来应对.这就会出现一个系统中可能会访问多处数据库,需要配置多个数据源. 第一种场景:项目服务从其它多处数据库取基础数据进行业务 ...
- Java 添加、删除Excel表单控件
通过表单控件,用户可以快速地将数据填写到模板文档中,轻松引用单元格数据并与其进行交互.本文通过Java代码示例介绍如何在Excel表格中添加表单控件,包括文本框.单选按钮.复选框.组合框.微调按钮等: ...
- css 重排与重绘
css 重绘与重排 我们要知道当浏览器下载完页面的所有资源后,就会开始解析源代码. HTML 会被解析成 DOM Tree,Css 则会被渲染成 CSSOM Tree,最后它们会附加到一起,形成渲染树 ...