当前位置: 首页 > 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;希望可以给有需求的小伙伴一些帮助 目录 一、设计要求 二、…...

基于Uniapp开发HarmonyOS 5.0旅游应用技术实践

一、技术选型背景 1.跨平台优势 Uniapp采用Vue.js框架&#xff0c;支持"一次开发&#xff0c;多端部署"&#xff0c;可同步生成HarmonyOS、iOS、Android等多平台应用。 2.鸿蒙特性融合 HarmonyOS 5.0的分布式能力与原子化服务&#xff0c;为旅游应用带来&#xf…...

C++:多态机制详解

目录 一. 多态的概念 1.静态多态&#xff08;编译时多态&#xff09; 二.动态多态的定义及实现 1.多态的构成条件 2.虚函数 3.虚函数的重写/覆盖 4.虚函数重写的一些其他问题 1&#xff09;.协变 2&#xff09;.析构函数的重写 5.override 和 final关键字 1&#…...

C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...

基于Java+VUE+MariaDB实现(Web)仿小米商城

仿小米商城 环境安装 nodejs maven JDK11 运行 mvn clean install -DskipTestscd adminmvn spring-boot:runcd ../webmvn spring-boot:runcd ../xiaomi-store-admin-vuenpm installnpm run servecd ../xiaomi-store-vuenpm installnpm run serve 注意&#xff1a;运行前…...

毫米波雷达基础理论(3D+4D)

3D、4D毫米波雷达基础知识及厂商选型 PreView : https://mp.weixin.qq.com/s/bQkju4r6med7I3TBGJI_bQ 1. FMCW毫米波雷达基础知识 主要参考博文&#xff1a; 一文入门汽车毫米波雷达基本原理 &#xff1a;https://mp.weixin.qq.com/s/_EN7A5lKcz2Eh8dLnjE19w 毫米波雷达基础…...

数学建模-滑翔伞伞翼面积的设计,运动状态计算和优化 !

我们考虑滑翔伞的伞翼面积设计问题以及运动状态描述。滑翔伞的性能主要取决于伞翼面积、气动特性以及飞行员的重量。我们的目标是建立数学模型来描述滑翔伞的运动状态,并优化伞翼面积的设计。 一、问题分析 滑翔伞在飞行过程中受到重力、升力和阻力的作用。升力和阻力与伞翼面…...

mac:大模型系列测试

0 MAC 前几天经过学生优惠以及国补17K入手了mac studio,然后这两天亲自测试其模型行运用能力如何&#xff0c;是否支持微调、推理速度等能力。下面进入正文。 1 mac 与 unsloth 按照下面的进行安装以及测试&#xff0c;是可以跑通文章里面的代码。训练速度也是很快的。 注意…...

简单介绍C++中 string与wstring

在C中&#xff0c;string和wstring是两种用于处理不同字符编码的字符串类型&#xff0c;分别基于char和wchar_t字符类型。以下是它们的详细说明和对比&#xff1a; 1. 基础定义 string 类型&#xff1a;std::string 字符类型&#xff1a;char&#xff08;通常为8位&#xff09…...

深入解析 ReentrantLock:原理、公平锁与非公平锁的较量

ReentrantLock 是 Java 中 java.util.concurrent.locks 包下的一个重要类,用于实现线程同步,支持可重入性,并且可以选择公平锁或非公平锁的实现方式。下面将详细介绍 ReentrantLock 的实现原理以及公平锁和非公平锁的区别。 ReentrantLock 实现原理 基本架构 ReentrantLo…...

【多线程初阶】单例模式 指令重排序问题

文章目录 1.单例模式1)饿汉模式2)懒汉模式①.单线程版本②.多线程版本 2.分析单例模式里的线程安全问题1)饿汉模式2)懒汉模式懒汉模式是如何出现线程安全问题的 3.解决问题进一步优化加锁导致的执行效率优化预防内存可见性问题 4.解决指令重排序问题 1.单例模式 单例模式确保某…...