Android开发之滑动菜单(八)

news2024/10/6 20:27:02

文章目录

  • Android菜单使用(Menu)
      • 菜单分类
      • 滑动菜单使用步骤
    • 滑动菜单
      • 先实现一个简单的滑动菜单步骤:
      • 使用NavigationView控件丰富滑动菜单图像内容
        • 效果展示

Android菜单使用(Menu)

菜单分类

  1. 选项菜单
    • 产生对应全局影响的操作。eg.更改页面布局等
  2. 上下文菜单
    • 长按时产生的浮动菜单(出现位置不确定)【直接影响对应内容】
  3. 侧滑菜单
    • 展示个人信息的菜单
  4. 动作菜单
    • 允许用户的多选操作
  5. 弹出菜单
    • 适用于提供特定内容相关的大量操作中,或者为命令的另一部分提供选项。【不直接影响对应内容】

滑动菜单使用步骤

  1. 定义菜单资源文件(自定义样式)
  2. 布局管理使用DrawerLayout+NavigationView结和分别定义了主屏幕显示的内容侧滑菜单显示的内容
  3. 给初始化的侧滑菜单设置事件监听

滑动菜单

先实现一个简单的滑动菜单步骤:

  1. 使用DrawerLayout布局管理:

包全名:androidx.drawerlayout.widget.DrawerLayout

主页面使用FrameLayout占满屏幕,辅页面也需要占满整个屏幕(这是使用DrawerLayout的刚需

具体实现如下(我再Toolbar中内嵌了一个图标)

<?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"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
            <ImageView
                android:id="@+id/menus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@mipmap/home_menu"/>
        </androidx.appcompat.widget.Toolbar>
    </FrameLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:text="This is menu"
        android:textSize="30sp"
        android:background="#ffff00"/>

</androidx.drawerlayout.widget.DrawerLayout>

使用NavigationView控件丰富滑动菜单图像内容

注意:需要在mipmap中添加三张icon图片

<!--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"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
            <ImageView
                android:id="@+id/menus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@mipmap/home_menu"/>
        </androidx.appcompat.widget.Toolbar>
    </FrameLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="false"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>
<!--nav_header_main.xml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="176dp"
    android:background="@color/color_blue"
    android:gravity="bottom"
    android:orientation="vertical"
    android:padding="16dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nav_header_desc"
        android:paddingTop="16dp"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        android:text="@string/nav_header_title"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nav_header_subtitle" />
</LinearLayout>
<!--activity_main_drawer.xml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="176dp"
    android:background="@color/color_blue"
    android:gravity="bottom"
    android:orientation="vertical"
    android:padding="16dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nav_header_desc"
        android:paddingTop="16dp"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
        android:text="@string/nav_header_title"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nav_header_subtitle" />
</LinearLayout>
效果展示

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1864832.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

忘了SD3 Medium吧!SD【写实大模型】逼真! 震撼!胶片风真实感大模型——LEOSAM‘s MoonFilm V2

hello&#xff0c;大家好我是安琪&#xff0c; 虽然SD3 Medium模型已经推出一段时间&#xff0c;应该也不少朋友和老徐一样&#xff0c;非常期待基于 SD3 微调的模型能有更好的表现力&#xff0c;但随着近期C站对SD3 微调模型的封杀&#xff0c;目前还没有见到太多SD3的其他模…

FPGA开发技能(7)Vivado设置bit文件加密

文章目录 前言1. AES加密原理2.xilinx的AES方案3.加密流程3.1生成加密的bit流3.2将密钥写入eFUSE寄存器 4.验证结论5.传送门 前言 在FPGA的项目发布的时候需要考虑项目工程加密的问题&#xff0c;一方面防止自己的心血被盗&#xff0c;另一方面也保护公司资产&#xff0c;保护知…

yolo-world使用自己数据集训练

YOLO-World下载&#xff1a; https://github.com/AILab-CVC/YOLO-World/tree/master 1.数据准备 数据格式COCO格式即可 2.配置文件修改 configs/finetune_coco/yolo_world_v2_l_vlpan_bn_sgd_1e-3_40e_8gpus_finetune_coco.py &#xff08;1&#xff09; 模型下载路径&#xf…

六载深耕结硕果 重任千钧再出发——福建又一物联网项目交付

在福建这片充满活力的土地上&#xff0c;唯众以其深厚的技术积淀和专业实力&#xff0c;在物联网教育领域深耕多年&#xff0c;为培养新时代的技术人才贡献着自己的力量。近日&#xff0c;漳州技师学院物联网应用技术专业实训室建设项目的成功交付&#xff0c;再次证明了唯众在…

Java25年还有更多的工作岗位适合二本学生就业吗?

Java作为一种广泛使用的编程语言。尽管技术领域不断发展和变化&#xff0c;Java依然在许多行业中占据重要地位。以下是一些原因&#xff0c;刚好我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「JAVA的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区…

权限传递,提取明文密码

一、cs与msf权限传递 创建foreign监听器-->msf监听模块设置端口-->cs执行新建会话选择创建的监听器 1.创建监听器&#xff1a; 2.msf监听设置端口&#xff1a; use exploit/multi/hander set payload windows/meterpreter/reverse_http set lport 4444 exploit 二、mi…

数据质量管理-一致性管理

前情提要 根据GB/T 36344-2018《信息技术 数据质量评价指标》的标准文档&#xff0c;当前数据质量评价指标框架中包含6评价指标&#xff0c;在实际的数据治理过程中&#xff0c;存在一个关联性指标。7个指标中存在4个定性指标&#xff0c;3个定量指标&#xff1b; 定性指标&am…

运维入门技术——监控的三个维度(非常详细)零基础收藏这一篇就够了_监控维度怎么区分

一个好的监控系统最后要做到的形态:实现Metrics、Tracing、Logging的融合。监控的三个维度也就是Metrics、Tracing、Logging。 Metrics Metrics也就是我们常说的指标。 首先它的典型特征就是可聚合(aggregatable).什么是可聚合的呢,简单讲可聚合就是一种基本单位可以在一种维…

Rust详解日志

详解日志 相比起监控&#xff0c;日志好理解的多&#xff1a;在某个时间点向指定的地方输出一条信息&#xff0c;里面记录着重要性、时间、地点和发生的事件&#xff0c;这就是日志。 注意&#xff0c;本文和 Rust 无关&#xff0c;我们争取从一个中立的角度去介绍何为日志 日…

防火墙GRE over IPSec配置

一、基础知识 1、GRE隧道 GRE隧道是一种网络通信协议&#xff0c;使用通用路由封装&#xff08;GRE&#xff09;技术&#xff0c;能够将一种网络协议下的数据报文封装在另一种网络协议中&#xff0c;从而实现在另一个网络层协议中的传输。 GRE隧道的基本概念和工作方式 基本…

Ubuntu磁盘分区和挂载 虚拟机扩容 逻辑卷的创建和扩容保姆及教程

目录 1、VMware虚拟机Ubuntu20.04系统磁盘扩容 2、Linux的磁盘分区和挂载 3、创建逻辑卷和逻辑卷的扩容 1、VMware虚拟机Ubuntu20.04系统磁盘扩容 通过下图可以看出我们的根磁盘一共有20G的大小&#xff0c;现在我们把它扩容为30G 注&#xff1a;如果你的虚拟机有快照是无…

2024年JCR分区,将发生重大变化

科睿唯安官方微信发布消息&#xff0c;指出今年的期刊排名及相应JCR分区将发生重大变化。 原文比较长&#xff0c;不熟悉相关规则的朋友也不太容易读懂。因此&#xff0c;我们今天做一个详细的解读。 首先明确几个基本概念&#xff1a; &#xff08;1&#xff09;2024年发布2…

如何通过IPXProxy动态住宅代理增强网络安全与隐私?

​在当今互联网技术日新月异的背景下&#xff0c;动态住宅代理已成为网络运营和数据收集中不可或缺的关键工具。本文将深入探讨动态住宅代理在提升网络安全性和隐私保护方面的重要性。 动态住宅代理与隐私保护 动态住宅代理通过代理服务器连接至互联网&#xff0c;为用户的原始…

2024年二级建造师机电工程专业考试题库分享。

1.调查表法通常与&#xff08;&#xff09;结合使用&#xff0c;以便更快地发现问题原因。 A.经验法 B.分层法 C.样本调查法 D.对比分析法 答案&#xff1a;B 解析&#xff1a;题干内容提示调查表法往往会与分层法结合起来应用&#xff0c;故B选项正确。 2.在质量统计分…

RAG | (ACL24规划-检索增强)PlanRAG:一种用于生成大型语言模型作为决策者的规划检索增强生成方法

原文&#xff1a;PlanRAG: A Plan-then-Retrieval Augmented Generation for Generative Large Language Models as Decision Makers 地址&#xff1a;https://arxiv.org/abs/2406.12430 代码&#xff1a;https://github.com/myeon9h/PlanRAG 出版&#xff1a;ACL 24 机构: 韩国…

vue3中通过vditor插件实现自定义上传图片、录入echarts、脑图、markdown语法的编辑器

1、下载Vditor插件 npm i vditor 我的vditor版本是3.10.2&#xff0c;大家可以自行选择下载最新版本 官网&#xff1a;Vditor 一款浏览器端的 Markdown 编辑器&#xff0c;支持所见即所得&#xff08;富文本&#xff09;、即时渲染&#xff08;类似 Typora&#xff09;和分屏 …

RT-Thread Studio实现静态线程

1创建项目 &#xff08;STM32F03ZET6&#xff09; RT-Thread项目与RT-Thread Nano 项目区别 RT-Thread: 完整版&#xff1a;这是RT-Thread的完整形态&#xff0c;适用于资源较丰富的物联网设备。功能&#xff1a;它提供了全面的中间件组件&#xff0c;如文件系统、网络协议栈、…

MS31011低压 5V DC 电机驱动

MS31011 是一款低压 5V 直流电机驱动芯片&#xff0c;为摄像机、消 费类产品、玩具和其他低压或者电池供电的运动控制类应用提 供了集成的电机驱动解决方案。 MS31011 能提供高达 0.8A 的输出电流。可以工作在 2.0~5.5V 的电源电压上。 MS31011 具有 PWM &#x…

比特币生态系统的现状与流动性提升的新路径

自2009年中本聪发布比特币白皮书以来&#xff0c;比特币一直被誉为“数字黄金”&#xff0c;在加密货币领域占据着不可动摇的地位。其去中心化、稀缺性和安全性&#xff0c;增强了其作为长期价值储存工具的吸引力。 相比之下&#xff0c;以太坊自2015年问世以来&#xff0c;凭…

oceanbase数据库安装和连接实战(阿里云服务器操作)

本文主要是安装oceanbase的单机版进行数据库的基础使用&#xff0c;oceanbase的数据库是兼容mysql数据库的&#xff0c;实际的兼容程度需要更深度的测试&#xff0c;本文主要是安装oceanbase并使用SQLynx的mysql驱动连接使用oceanbase数据库。 目录 1. 基础介绍 2. 安装说明 …