安卓开发,底部导航栏

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>

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

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

相关文章

前后端服务配置

1、安装虚拟机&#xff08;VirtualBox或者vmware&#xff09;&#xff0c;在虚拟机上配置centos(选择你需要的Linux版本)&#xff0c;配置如nginx服务器等 1.1 VMware 下载路径Sign In注册下载 1.2 VirtualBox 下载路径https://www.virtualbox.org/wiki/Downloads 2、配置服…

亲身经历!!解决fatal: unable to access ‘https://~.git/‘: Failed to connect to github.com ····

最近学着用GitBash,发现上来gitclone 就报错。由于我是纯小白&#xff0c;所以试了比较多次&#xff0c;终于成功了。 首先我试了一下关闭梯子&#xff0c;发现还是不行。上网搜&#xff0c;说是代理问题&#xff0c;可我也不知道啥叫代理&#xff0c;反正大概意思就是电脑连通…

TCP传输层协议

TCP 全称为 "传输控制协议(Transmission Control Protocol"). 人如其名, 要对数据的传 输进行一个详细的控制。 对于TCP的学习主要就是要知道TCP协议报头之中各个字段的作用 除了数据之外总共报头加起来是20个字节 16位源端口号与目的端口号 这是最容易理解的两…

正则引入store中的modules文件

正则引入store中的modules文件 // index.js import { createStore } from vuex;const modulesFiles require.context(./modules, true, /\.ts|js$/); const modules modulesFiles.keys().reduce((modules1, modulePath) > {const moduleName modulePath.replace(/^\.\/(.…

127,【3】 buuctf [NPUCTF2020]ReadlezPHP

进入靶场 吓我一跳 查看源码 点击 审计 <?php// 定义一个名为 HelloPhp 的类&#xff0c;该类可能用于执行与日期格式化相关的操作 class HelloPhp {// 定义一个公共属性 $a&#xff0c;用于存储日期格式化的模板public $a;// 定义一个公共属性 $b&#xff0c;用于存储…

如何在浏览器中搭建开源Web操作系统Puter的本地与远程环境

文章目录 前言1.关于Puter2.本地部署Puter3.Puter简单使用4. 安装内网穿透5.配置puter公网地址6. 配置固定公网地址 前言 嘿&#xff0c;小伙伴们&#xff01;是不是每次开机都要像打地鼠一样不停地点击各种网盘和应用程序的登录按钮&#xff0c;感觉超级麻烦&#xff1f;更让…

产品详情页中 品牌官网详情 对应后端的字段是 detail

文章目录 1、在这个Vue代码中&#xff0c;品牌官网详情 对应后端的字段是 detail2、品牌官网详情 功能相关的代码片段3、export const productSave (data: any) >4、ProductController5、ProductDto 类6、ProductApiService 1、在这个Vue代码中&#xff0c;品牌官网详情 对…

51单片机(国信长天)矩阵键盘的基本操作

在CT107D单片机综合训练平台上&#xff0c;首先将J5处的跳帽接到1~2引脚&#xff0c;使按键S4~S19按键组成4X4的矩阵键盘。在扫描按键的过程中&#xff0c;发现有按键触发信号后(不做去抖动)&#xff0c;待按键松开后&#xff0c;在数码管的第一位显示相应的数字:从左至右&…

VSCode + Continue 实现AI编程助理

安装VS Code 直接官网下载安装&#xff0c;反正是免费的。 安装VS插件Continue 直接在插件市场中搜索&#xff0c; Continue&#xff0c;第一个就是了。 配置Chat Model 点击Add Chat model后进行选择&#xff1a; 选择Ollama后&#xff0c;需要点击下面的config file : 由于…

机器学习之数学基础:线性代数、微积分、概率论 | PyTorch 深度学习实战

前一篇文章&#xff0c;使用线性回归模型逼近目标模型 | PyTorch 深度学习实战 本系列文章 GitHub Repo: https://github.com/hailiang-wang/pytorch-get-started 本篇文章内容来自于 强化学习必修课&#xff1a;引领人工智能新时代【梗直哥瞿炜】 线性代数、微积分、概率论 …

BS架构(笔记整理)

楔子.基本概念 1.在网络架构中&#xff1a; 服务器通常是集中式计算资源&#xff0c;负责处理和存储数据&#xff1b;客户机是请求这些服务的终端设备&#xff0c;可能是个人电脑或移动设备&#xff1b;浏览器则是客户机上用来与服务器交互的工具&#xff0c;负责展示网页内容…

云消息队列 ApsaraMQ Serverless 演进:高弹性低成本、更稳定更安全、智能化免运维

如今&#xff0c;消息队列已成为分布式架构中不可或缺的关键服务&#xff0c;为电商、物联网、游戏和教育等行业&#xff0c;提供了异步解耦、集成、高性能和高可靠的核心价值。 过去一年&#xff0c;我们发布了云消息队列 ApsaraMQ 全系列产品 Serverless 化&#xff0c;面向…

python学opencv|读取图像(六十)先后使用cv2.erode()函数和cv2.dilate()函数实现图像处理

【1】引言 前序学习进程中&#xff0c;先后了解了使用cv2.erode()函数和cv2.dilate()函数实现图像腐蚀和膨胀处理的效果&#xff0c;相关文章链接为&#xff1a; python学opencv|读取图像&#xff08;五十八&#xff09;使用cv2.erode()函数实现图像腐蚀处理-CSDN博客 pytho…

apache-poi导出excel数据

excel导出 自动设置宽度&#xff0c;设置标题框&#xff0c;设置数据边框。 excel导出 添加依赖 <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.2</version></dependency>…

STM32EXTI外部中断

EXTI外部中断 中断&#xff1a;在主程序运行过程中&#xff0c;出现了特定的中断触发条件&#xff08;中断源&#xff09;&#xff0c;使得CPU暂停当前正在运行的程序&#xff0c;转而去处理中断程序&#xff0c;处理完成后又返回原来被暂停的位置继续运行&#xff08;有点像函…

kafka生产端之架构及工作原理

文章目录 整体架构元数据更新 整体架构 消息在真正发往Kafka之前&#xff0c;有可能需要经历拦截器&#xff08;Interceptor&#xff09;、序列化器&#xff08;Serializer&#xff09;和分区器&#xff08;Partitioner&#xff09;等一系列的作用&#xff0c;那么在此之后又会…

STM32 Unix时间戳

Unix时间戳 Unix 时间戳&#xff08;Unix Timestamp&#xff09;定义为从UTC/GMT的1970年1月1日0时0分0秒开始所经过的秒数&#xff0c;不考虑闰秒 时间戳存储在一个秒计数器中&#xff0c;秒计数器为32位/64位的整型变量 世界上所有时区的秒计数器相同&#xff0c;不同时区通过…

SSM仓库物品管理系统 附带详细运行指导视频

文章目录 一、项目演示二、项目介绍三、运行截图四、主要代码1.用户登录代码&#xff1a;2.保存物品信息代码&#xff1a;3.删除仓库信息代码&#xff1a; 一、项目演示 项目演示地址&#xff1a; 视频地址 二、项目介绍 项目描述&#xff1a;这是一个基于SSM框架开发的仓库…

[渗透测试]热门搜索引擎推荐— — shodan篇

[渗透测试]热门搜索引擎推荐— — shodan篇 免责声明&#xff1a;本文仅用于分享渗透测试工具&#xff0c;大家使用时&#xff0c;一定需要遵守相关法律法规。 除了shodan&#xff0c;还有很多其他热门的&#xff0c;比如&#xff1a;fofa、奇安信的鹰图、钟馗之眼等&#xff0…

绕组电感 - Ansys Maxwell 磁通链与电流

在本博客中&#xff0c;我将演示如何使用 Ansys Maxwell 中磁瞬态求解器的磁通链和电流结果来计算绕组电感。Ansys Maxwell 磁瞬态求解器在场计算中考虑了涡流效应&#xff0c;我将展示一种使用磁通链和电流结果来计算绕组电感的简单方法。 实际上&#xff0c;电感是非线性的…