BottomNavigationView是底部导览的控件,就像line下方的四个选项,今天我会分享BottomNavigationView的使用方法。
先Sync now此模组
implementation 'com.google.android.material:material:1.3.0-alpha01'
再来右键res新增menu资料夹
在menu资料夹里新增menu.xml
设定menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/setting"
android:icon="@drawable/ic_baseline_settings_24"
android:title="设定"/>
<item android:id="@+id/comment"
android:icon="@drawable/ic_baseline_comment_24"
android:title="意见"/>
<item android:id="@+id/account"
android:icon="@drawable/ic_baseline_account_circle_24"
android:title="个人资讯"/>
</menu>
在activity_main.xml新增BottomNavigationView,并将设定好的menu带入BottomNavigationView
<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">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#A9FFFFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
成果图
明天会分享BottomNavigationView切换画面
<<: [影片]第26天:物件导向程序设计-运算子(实例100~104)
>>: How to split a (HUGE) pcap file into a set of smaller ones ? keyword: tcpdump
前言 今天会接续着昨天的主题,来聊聊 The Clean Coder 的另一个主题。 在我过去的工作...
今天来说说如何在html中产生一个表格,我们需要用到table这个语法,table的用法如下 tab...
有些公司永远在徵人(人员一直在流动),实际去应徵过後,会深刻理解到为什麽。 前几天提到GitHub时...
甚麽是「Callback function」? MDN的解释如下: 「回呼函式(callback ...
前言 以TIMER为主要观察源,使用TIMER触发ADC,透过DMA结合,同时观察ADC中断副程序,...