[Lesson5] BottomNavigationView

首先在res资料夹下,新增menu的资料夹
https://ithelp.ithome.com.tw/upload/images/20210722/20129566Z7qYZ9ZS9S.png
https://ithelp.ithome.com.tw/upload/images/20210722/20129566ENsTKDyZw7.png

再来新增一个Menu resource file,取名为nav_bottom
https://ithelp.ithome.com.tw/upload/images/20210722/2012956618hGMQaitJ.png
https://ithelp.ithome.com.tw/upload/images/20210722/20129566a9TfteOhe6.png

进入到刚刚建立的nav_bottom之前,先在drawable新增几张图片,点击Vector Asset
https://ithelp.ithome.com.tw/upload/images/20210722/20129566dKMjEjZGwj.png

点击红色箭头所指的地方(Clip Art右边的图案上)
https://ithelp.ithome.com.tw/upload/images/20210722/20129566P7WG2g6mYQ.png

选择想要的图片
https://ithelp.ithome.com.tw/upload/images/20210722/201295662rgmM4JTbH.png

可以换个颜色,按下Next,就新增完成
https://ithelp.ithome.com.tw/upload/images/20210722/20129566MEBZuukBv0.png

然後进入到刚刚建立的nav_bottom,加入item(BottomView最多只支援五个)

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:title="主页"
        android:id="@+id/homePage"
        android:icon="@drawable/ic_baseline_home_24"/>

    <item android:title="角色"
        android:id="@+id/character"
        android:icon="@drawable/ic_baseline_person_24"/>

    <item android:title="剧情"
        android:id="@+id/plot"
        android:icon="@drawable/ic_baseline_menu_book_24"/>
</menu>

activity_main:
使用ConstraintLayout,再将元件一一放入

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    // 放fragment
    <FrameLayout
        android:id="@+id/frag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/nav_bottom"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

BottomNavigationView的功能,会放在下一篇文章与fragment进行应用/images/emoticon/emoticon41.gif


<<:  IT 铁人赛 k8s 入门30天 -- day6 主要 Kubectl 指令 - K8s CLI

>>:  DAY06随机森林演算法(续3)

【在厨房想30天的演算法】Day 05 资料结构之冰箱整理术

Aloha!又是我少女人妻 Uerica!昨晚跟朋友聊天突然发现,如果没有最终目标或目标不够明确,那...

【左京淳的JAVA WEB学习笔记】第五章 过滤器与监听器

过滤器可以用来做权限校验或是编码转换等功能。 多个过滤器可以串联在一起,做多重过滤。 自定义的过滤器...

[Day11]日期函数

这篇文章要介绍的是单列函数中的日期函数。 前面介绍的是单纯的日期单列函数,接下来列出一些简单的日期运...

【第十六天 - 动态规划 介绍】

Q1. 动态规划(Dynamic Programming)是什麽 ? Dynamic program...

CISSP考试资源

CISSP快速启动版(建议之最低要求) https://wentzwu.com/cissp-expr...