前言
大家好,我是 波士顿木木,今天给大家带来AndroidStudio制作底部导航栏以及用Fragment实现切换功能的概述,希望你们喜欢
学习目标
AndroidStudio制作底部导航栏以及用Fragment实现切换功能,用户点击底部导航栏可以实现三个模块的跳转。
拿QQ界面举例,我们不难发现,点击下面状态栏,除当前界面下的状态栏以外的上面部分界面会跳转到相应的另一个页面。我们今天就来实现这种效果。
一、前期准备
- 创建一个新的模块,将其命名为fragment:
- 再创建三个后面要实现相互切换的fragment:
- 创建好后的项目结构如下:
二、编写activity_main.xml
- 在页面底部添加三个约束布局做点击事件,再在上方添加一个id为layout的约束布局。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="&#