Android Studio3.5下创建的BottomNavigationView项目无法使用NoActionBar的处理

2023-05-16

        在使用Android Studio3.5下创建的BottomNavigationView项目时因为BottomNavigationView使用fragment控件的NavHostFragment进行Fragment切换,但却无法设置Activity的NoActionBar了,而且自定义每个Fragment的ActionBar也比较麻烦,所以就只能重写Fragment的切换方法。

        方法:在BottomNavigationView上自定义一个ViewPager包裹Fragment,对ViewPager进行切换。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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/container"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.example.demo.Tools.MyViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        tools:ignore="MissingConstraints" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom"
        app:itemBackground="@null"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/bottom_nav_menu" />

</LinearLayout>
具体方法,等有时间再贴上来

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Studio3.5下创建的BottomNavigationView项目无法使用NoActionBar的处理 的相关文章

随机推荐