首页 > 其他分享 >直播平台开发,Android Studio底部导航栏的实现

直播平台开发,Android Studio底部导航栏的实现

时间:2023-03-21 14:13:37浏览次数:50  
标签:layout fragment app id 直播 Studio Android navigation android

直播平台开发,Android Studio底部导航栏的实现

1、activity_main.xml

该界面布局为:BottomNavigationView+fragment。

 

在BottomNavigationView里,app:menu:底部导航栏按钮菜单。

 

在fragment里,app:navGraph:关联导航图。

 

 

<?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"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />//底部的导航按钮
 
    <fragment
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />//导航图
 
</androidx.constraintlayout.widget.ConstraintLayout>

2、bottom_nav_menu.xml菜单文件

在该文件里面定义底部的导航按钮,每一个item代表一个导航按钮。最多可显示五个导航按钮,开始系统默认创建3个导航按钮,可根据自己的需要自行添加。

 

说明:

 


android:icon<导航按钮显示的图标>
android:title<导航按钮显示的文字>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
 
    <item
        android:id="@+id/navigation_home"
        android:icon="@mipmap/bottom_btn1"
        android:title="账单" />
 
    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@mipmap/bottom_btn2"
        android:title="图表" />
 
    <item
        android:id="@+id/navigation_notifications"
        android:icon="@mipmap/bottom_btn3"
        android:title="记账" />
    <item
        android:id="@+id/navigation_blank"
        android:icon="@mipmap/bottom_btn5"
        android:title="我的" />
 
</menu>

 

3、mobile_navigation.xml

该文件的作用为:定义fragment。

 

说明:

 


每一个fragment的id与相应的底部导航按钮id需一致
navigation里:app:startDestination<指明开始默认的fragment>
fragment里:android:name<和它对应的Java类>
fragment里:android:label<界面顶部标题栏显示的文字>
fragment里:tools:layout<指明布局文件>
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/mobile_navigation"
    app:startDestination="@+id/navigation_home"> //开始默认显示的fragment
 
    <fragment
        android:id="@+id/navigation_home"
        android:name="com.example.ji_zhang_ben.ui.home.HomeFragment" 
        android:label="账单"
        tools:layout="@layout/fragment_home" />
 
    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.example.ji_zhang_ben.ui.dashboard.DashboardFragment"
        android:label="图表"
        tools:layout="@layout/fragment_dashboard" />
 
    <fragment
        android:id="@+id/navigation_notifications"
        android:name="com.example.ji_zhang_ben.ui.notifications.NotificationsFragment"
        android:label="记账"
        tools:layout="@layout/fragment_notifications" />
 
    <fragment
        android:id="@+id/navigation_blank"
        android:name="com.example.ji_zhang_ben.ui.blank.BlankFragment"
        android:label="我的"
        tools:layout="@layout/fragment_blank" />
</navigation>

 

 以上就是直播平台开发,Android Studio底部导航栏的实现, 更多内容欢迎关注之后的文章

 

标签:layout,fragment,app,id,直播,Studio,Android,navigation,android
From: https://www.cnblogs.com/yunbaomengnan/p/17239810.html

相关文章

  • 在线直播系统源码,顶部标题栏的隐藏和显示、标题修改
    在线直播系统源码,顶部标题栏的隐藏和显示、标题修改1、顶部标题栏的隐藏:在我们的project工程下,找到“values”文件夹下的“themes.xml”或“styles.xml”文件(文件位置一......
  • ​直播app开发搭建,Android Studio如何改变Button的背景颜色
    ​直播app开发搭建,AndroidStudio如何改变Button的背景颜色方法一:在XML中进行更改 <Button  android:id="@+id/B"  android:layout_width="match_parent"  ......
  • 一手遮天 Android - Resource: 读取 meta-data 数据
    项目地址https://github.com/webabcd/AndroidDemo作者webabcd一手遮天Android-Resource:读取meta-data数据示例如下:/resource/MetaDataDemo1.java/***......
  • 一手遮天 Android - UI: 闪屏页(启动页)
    项目地址https://github.com/webabcd/AndroidDemo作者webabcd一手遮天Android-UI:闪屏页(启动页)示例如下:/SplashActivity.java/***闪屏页(启动页)**程......
  • Android开发-Android操作系统简介
    01.  系统简介1.1 Android名词Android一词的本义指“机器人”,同时也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统、......
  • Android Studio通过jdbc连接MySQL
    1、下载MySQL-connector-jave.jar包地址如下:https://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.46 2、将jar包移到如图所示的位置,然后右键addasl......
  • ArcGIS Runtime for Android 3 Hello World
    本文分享如何一个新建项目HelloWorld,并重点说明如何模拟调试。一、新建项目现在的软件越来越方便,选择模板,直接新建项目即可。输出路径为自定义的D:\Android\Project......
  • Android studio学习笔记
    wrap_content内容有多少,它的宽度有多少match_parent匹配父空间,上一级宽度多少,这一级多少使用宽度长度自定义的时候最好用dp,因为Android屏幕碎片化比较严重,在不同的系统......
  • Android资源的使用之String
    Android允许定义多个字符串资源文件在res/values中<?xmlversion="1.0"encoding="utf-8"?><resources><stringname="hello">HelloWorld!</string><stringnam......
  • android ImageButton示例
    packagecom.xiaohang;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.app.Dialog;importandroid.app.AlertDialog.Builder;impo......