当前位置: 首页 > news >正文

安卓开发,底部导航栏

1、创建导航栏图标

使用系统自带的矢量图库文件,鼠标右键点击res->New->Vector Asset

修改 Name , Clip art 和 Color

 再创建一个

同样的方法再创建四个按钮

2、添加百分比布局依赖

app\build.gradle.kts 中添加百分比布局依赖,并点击Sync Now

implementation("androidx.percentlayout:percentlayout:1.0.0")

3、创建三个Layout Resource File

1)home.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.PercentRelativeLayoutxmlns: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:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentTop="true"android:text="主页"android:textSize="15pt"android:gravity="center"android:textColor="@color/black"android:background="#F0E7D8"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentBottom="true"android:background="#F0E7D8"><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/home_click"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="主页"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/learn"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/learn"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="学习"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/me"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/me"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="我"android:gravity="center"/></LinearLayout></LinearLayout>
</androidx.percentlayout.widget.PercentRelativeLayout>

2)learn.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.PercentRelativeLayoutxmlns: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:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentTop="true"android:text="学习"android:textSize="15pt"android:gravity="center"android:textColor="@color/black"android:background="#F0E7D8"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentBottom="true"android:background="#F0E7D8"><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/home"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/home"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="主页"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/learn_click"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="学习"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/me"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/me"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="我"android:gravity="center"/></LinearLayout></LinearLayout>
</androidx.percentlayout.widget.PercentRelativeLayout>

3)me.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.PercentRelativeLayoutxmlns: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:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentTop="true"android:text="我"android:textSize="15pt"android:gravity="center"android:textColor="@color/black"android:background="#F0E7D8"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_heightPercent="7%"android:layout_alignParentBottom="true"android:background="#F0E7D8"><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/home"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/home"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="主页"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:id="@+id/learn"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/learn"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="学习"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageButtonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#F0E7D8"android:src="@drawable/me_click"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="我"android:gravity="center"/></LinearLayout></LinearLayout>
</androidx.percentlayout.widget.PercentRelativeLayout>

4、创建三个Java Class

1)Home.java

package com.example.bottomnavigationbar;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.appcompat.app.AppCompatActivity;
public class Home extends AppCompatActivity {private ImageButton learn,me;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.home);learn = findViewById(R.id.learn);me = findViewById(R.id.me);learn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToLearn = new Intent(Home.this,Learn.class);startActivity(intentToLearn);overridePendingTransition(0, 0); // 取消转场动画}});me.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToMe = new Intent(Home.this,Me.class);startActivity(intentToMe);overridePendingTransition(0, 0); // 取消转场动画}});}
}

2)Learn.java

package com.example.bottomnavigationbar;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class Learn extends AppCompatActivity {private ImageButton home,me;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.learn);home = findViewById(R.id.home);me = findViewById(R.id.me);home.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToLearn = new Intent(Learn.this,Home.class);startActivity(intentToLearn);overridePendingTransition(0, 0); // 取消转场动画}});me.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToMe = new Intent(Learn.this,Me.class);startActivity(intentToMe);overridePendingTransition(0, 0); // 取消转场动画}});}
}

3)Me.java

package com.example.bottomnavigationbar;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class Me extends AppCompatActivity {private ImageButton home,learn;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.me);home = findViewById(R.id.home);learn = findViewById(R.id.learn);learn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToLearn = new Intent(Me.this,Learn.class);startActivity(intentToLearn);overridePendingTransition(0, 0); // 取消转场动画}});home.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intentToMe = new Intent(Me.this,Home.class);startActivity(intentToMe);overridePendingTransition(0, 0); // 取消转场动画}});}
}

5、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.BottomNavigationBar"tools:targetApi="31"><activityandroid:name=".Home"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".Learn"/><activity android:name=".Me"/></application>
</manifest>

相关文章:

安卓开发,底部导航栏

1、创建导航栏图标 使用系统自带的矢量图库文件&#xff0c;鼠标右键点击res->New->Vector Asset 修改 Name , Clip art 和 Color 再创建一个 同样的方法再创建四个按钮 2、添加百分比布局依赖 app\build.gradle.kts 中添加百分比布局依赖&#xff0c;并点击Sync Now …...

CWOI-N RER 1 > 2 Solution

CWOI-N RER 1 > 2 Solution 声明&#xff1a;头图为断章取义。 这场比赛得 200 200 200 分是保底&#xff0c;得 300 300 300 分是基操&#xff0c;得 350 350 350 分以上才是实力&#xff08;但不多&#xff09;。 A - 机读卡 No solutions yet. 这题数据倒还不能无…...

字节跳动后端一面

&#x1f4cd;1. Gzip压缩技术详解 Gzip是一种流行的无损数据压缩格式&#xff0c;它使用DEFLATE算法来减少文件大小&#xff0c;广泛应用于网络传输和文件存储中以提高效率。 &#x1f680; 使用场景&#xff1a; • 网站优化&#xff1a;通过压缩HTML、CSS、JavaScript文件来…...

Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题

Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题 背景 在使用 Dify 框架进行开发时&#xff0c;遇到了两个主要的技术挑战&#xff1a; 代码节点连接到 PGSQL&#xff08;PostgreSQL&#xff09;数据库。解决沙盒环境中由于系统调用限制导致的“oper…...

ModuleJS 与 CommonJS 混用的两种解决方案

目录 方案一 方案二 统一使用 ModuleJS 统一使用CommonJS 方案一 使用构建工具&#xff0c;webpack、vite等系列构建工具。这些构建工具底层则会将两种不同的系统模块语言转为同一种语言&#xff0c;然后代码也能正常执行。 方案二 如果你可以修改文件的文件后缀&#xf…...

代码随想录--977有序数组的平方

977 有序数组的平方 题目&#xff1a; 给你一个按 非递减顺序 排序的整数数组 nums&#xff0c;返回 每个数字的平方 组成的新数组&#xff0c;要求也按 非递减顺序 排序。 示例 1&#xff1a; 输入&#xff1a;nums [-4,-1,0,3,10] 输出&#xff1a;[0,1,9,16,100] 解释&…...

Win11下搭建Kafka环境

目录 一、环境准备 二、安装JDK 1、下载JDK 2、配置环境变量 3、验证 三、安装zookeeper 1、下载Zookeeper安装包 2、配置环境变量 3、修改配置文件zoo.cfg 4、启动Zookeeper服务 4.1 启动Zookeeper客户端验证 4.2 启动客户端 四、安装Kafka 1、下载Kafka安装包…...

MacBook Pro M2安装deepseek

序 本文主要展示一下如何在MacBook Pro M2安装deepseek mac配置 芯片Apple M2&#xff0c;8核(物理)&#xff0c;内存16G&#xff0c;os版本Ventura&#xff0c;磁盘500G 步骤 下载ollama 去https://ollama.com/下载mac版本 或者使用go来编译 git clone --depth 1 http…...

springboot的http请求不通原因

Spring Boot 应用中 HTTP 请求不通可能由多种原因引起&#xff0c;以下是一些常见问题及解决方法&#xff1a; 1. 端口冲突 问题&#xff1a;应用端口被占用。 解决&#xff1a;检查端口占用情况&#xff0c;修改 application.properties 或 application.yml 中的端口配置。 …...

【Windows】PowerShell 缓存区大小调节

PowerShell 缓存区大小调节 方式1 打开powershell 窗口属性调节方式2&#xff0c;修改 PowerShell 配置文件 方式1 打开powershell 窗口属性调节 打开 CMD&#xff08;按 Win R&#xff0c;输入 cmd&#xff09;。右键标题栏 → 选择 属性&#xff08;Properties&#xff09;…...

使用python脚本批量删除redis缓存

首先&#xff0c;安装 redis-py 库&#xff1a; pip install redis 其次&#xff0c;创建一个 Python 脚本来连接到 Redis 并删除匹配的键。假设 Redis 端口是 6379&#xff0c;密码是 mypassword&#xff08;如果有密码的话&#xff09;。 import redis# 连接到 Redis r r…...

Python截图轻量化工具

一、兼容局限性 这是用Python做的截图工具&#xff0c;不过由于使用了ctypes调用了Windows的API, 同时访问了Windows中"C:/Windows/Cursors/"中的.cur光标样式文件, 这个工具只适用于Windows环境&#xff1b; 如果要提升其跨平台性的话&#xff0c;需要考虑替换cty…...

Android图片加载框架Coil,Kotlin

Android图片加载框架Coil&#xff0c;Kotlin implementation("io.coil-kt:coil:1.4.0") import android.os.Bundle import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import coil.Coil i…...

重生之我要当云原生大师(十四)分析和存储日志

目录 一、简述常用的日志文件所存储的消息类型。 二、syslog的优先级&#xff1f; 三、维护准确时间的意义&#xff1f; 一、简述常用的日志文件所存储的消息类型。 1. 系统日志文件 /var/log/messages 消息类型&#xff1a;通用的系统日志文件&#xff0c;记录系统启动、…...

C++基础知识学习记录—补充

1、C新增的赋值语法 #include <iostream>using namespace std;int main() {//C新的赋值语法//1、传统的赋值语法int a,b;a100;b99;//C新的赋值语法int c(2);//相当于给c赋值2int d(c);//相当于把c的值赋值给dcout << "c" << c << endl;co…...

Linux常用命令——磁盘管理类

文章目录 du 查看文件和目录占用的磁盘空间df 查看磁盘空间使用情况free 显示内存占用情况lsblk 查看设备挂载情况mount/umount 挂载/卸载fdisk 分区Linux分区分区操作按键说明挂载硬盘操作 du 查看文件和目录占用的磁盘空间 ls-lh是查看文件大小du: disk usage 磁盘占用情况d…...

【AI学习】DeepSeek为什么强?

个人的一些思考&#xff0c;请大家批评指正。 这个问题&#xff0c;首先当然是在恰当的时间出现&#xff0c;模型性能跻身世界一流&#xff0c;又开源&#xff0c;戳破了OpenAI和英伟达潜心构造的叙事逻辑。 DeepSeek为什么强&#xff1f;四个方面&#xff1a;模型的智能水平…...

【快应用】原生广告下载状态监听案例

问题背景&#xff1a; 快应用中下载类原生广告监听下载状态变化接口调用没生效&#xff0c;在上报点击接口里触发下载监听后仅第一次返回状态&#xff0c;之后就不返回了&#xff0c;该如何处理&#xff1f; 问题分析&#xff1a; 快应用在1100版本新增了一个ad-button组件&a…...

C++语言的软件工程

C语言的软件工程 引言 在当今快速发展的技术领域&#xff0c;软件工程作为一门综合性的学科&#xff0c;越来越受到重视。而C语言&#xff0c;作为一种功能强大且具有广泛应用的编程语言&#xff0c;在软件工程中占据着重要的地位。本文将探讨C语言在软件工程中的应用与特点&…...

计算机网络结课设计:通过思科Cisco进行中小型校园网搭建

上学期计算机网络课程的结课设计是使用思科模拟器搭建一个中小型校园网&#xff0c;当时花了几天时间查阅相关博客总算是做出来了&#xff0c;在验收后一直没管&#xff0c;在寒假想起来了简单分享一下&#xff0c;希望可以给有需求的小伙伴一些帮助 目录 一、设计要求 二、…...

AI大模型应用开发全攻略:从入门到精通,掌握LLM、RAG、Agent核心技能!“

本文全面介绍了AI大模型应用开发的核心技术和实践。从大模型API交互基础&#xff0c;到关键参数Messages和Tools的作用&#xff0c;深入解析了RAG、ReAct、Agent等应用范式。文章还探讨了Fine-tuning微调和Prompt提示词工程的重要性&#xff0c;强调工程实践与业务需求相结合。…...

硬件答辩问题总结

一、电源纹波是什么&#xff0c;为什么LDO的小&#xff0c;DCDC的大1.电源纹波电源纹波 是指直流电源输出电压上叠加的 交流波动成分&#xff0c;表现为电压在理想直流值附近上下波动。2.LDO 纹波小原理LDO 内部是一个 调整管&#xff08;可变电阻&#xff09; 串联在输入和输出…...

HFSS仿真结果怎么看?一文读懂S参数与电场图,让你的T型波导分析不再迷茫

HFSS仿真结果深度解析&#xff1a;从S参数到电场图的工程实践指南面对HFSS仿真生成的复杂数据图表&#xff0c;许多工程师常陷入"看得见数据却读不懂含义"的困境。本文将带您穿透数据表象&#xff0c;掌握T型波导性能分析的核心方法论。1. S参数&#xff1a;波导性能…...

ThinkPad开机报错0183/0253?别慌,手把手教你搞定EFI变量错误(附BIOS重置教程)

ThinkPad开机报错0183/0253&#xff1f;EFI变量错误全面解决方案当你按下ThinkPad的电源键&#xff0c;期待熟悉的开机画面时&#xff0c;屏幕上却突然跳出一串神秘代码——"0183: Bad CRC of Security Settings in EFI Variable"或"0253: EFI Variable Block D…...

Windows 10/11系统下,SecureCRT 8.7.2保姆级安装与激活图文指南(含Keygen使用避坑点)

Windows平台SecureCRT 8.7.2全流程部署与安全配置指南在当今远程运维与网络管理的日常工作中&#xff0c;一款可靠的终端仿真工具如同工程师的瑞士军刀。作为行业标杆的SecureCRT&#xff0c;其8.7.2版本在Windows 10/11环境下的部署却常让新手陷入各种技术陷阱——从安装路径选…...

[智能体-81]:工程化智能体 = 模型做脑力拆解 + 框架做流程落地。前者是决策者,后者是管理者,tools/function call是内部员工;mcp server是外部资源;

一、全角色人设 & 对应技术组件角色定位对应技术模块核心职责决策者&#xff08;脑力大脑&#xff09;大模型 LLM理解目标、任务拆解、逻辑判断、分支决策、内容生成&#xff0c;负责 “想方案、定步骤”管理者&#xff08;流程总管&#xff09;智能体编排框架&#xff08;…...

ROS Noetic实战:从bag包里‘抠’出雷达点云和IMU数据的保姆级教程(Ubuntu 20.04)

ROS Noetic实战&#xff1a;从bag包里提取雷达点云和IMU数据的完整指南&#xff08;Ubuntu 20.04&#xff09;在机器人开发中&#xff0c;ROS bag文件就像是一个装满珍贵数据的宝箱&#xff0c;而雷达点云和IMU数据则是其中最闪亮的宝石。作为一名长期与ROS打交道的开发者&…...

AI学习 - 大模型基础入门

AI学习 - 大模型基础入门 从零开始&#xff1a;Ollama 安装 → 本地模型运行 → Python 代码接入 → 理解核心概念 摘要 本文记录了在 Windows 上使用 Ollama 部署本地大模型、并通过 Python 代码接入调用的完整过程。内容涵盖&#xff1a;Ollama 安装与模型拉取、大模型基础概…...

AI圈神秘领袖Ilya一幅画引爆全网,OpenAI三件大事暗示AGI时代将至?

AI圈神秘精神领袖Ilya在Instagram上传一幅画引发疯狂解读&#xff0c;与此同时&#xff0c;OpenAI连续公布数学成果、升级Codex、筹备IPO&#xff0c;释放AGI到来的强烈信号。Ilya画作引猜测Ilya上传的画中&#xff0c;罗丹的「思考者」踩在芯片Die Shot上&#xff0c;右下角签…...

深度解析网络设备权限管理工具:中兴光猫工厂模式与Telnet服务完整指南

深度解析网络设备权限管理工具&#xff1a;中兴光猫工厂模式与Telnet服务完整指南 【免费下载链接】zteOnu A tool that can open ZTE onu device factory mode 项目地址: https://gitcode.com/gh_mirrors/zt/zteOnu 在当今网络设备管理领域&#xff0c;获取设备完整控制…...