具有导航控制事务的底部导航视图有时失败

时间:2019-08-07 10:16:15

标签: android-studio bottomnavigationview android-jetpack android-jetpack-navigation

有时我在获取应用程序主题颜色应用于输入片段时,有时从底部导航视图的一个选项卡移至另一个选项卡

这是我的代码

``活动代码''`

重写onSupportNavigateUp()= NavigationUI.navigateUp(navController !!,null)

private fun setUpNavigation() {
    navController = Navigation.findNavController(this, R.id.frameRoot)
    bottomNavigationView.setupWithNavController(navController)

    bottomNavigationView.setOnNavigationItemSelectedListener { item ->
        onNavDestinationSelected(item, navController)
    }
}

布局设计

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <fragment
            android:id="@+id/frameRoot"
            android:layout_width="match_parent"
            android:name="androidx.navigation.fragment.NavHostFragment"
            app:defaultNavHost="true"
            android:layout_height="match_parent"
            app:navGraph="@navigation/dashboard_graph"
            android:layout_above="@+id/navigation"
            android:background="@color/white_color"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom"
            android:background="#FFFFFF"
            style="@style/AppTheme.BottomDark"
            android:visibility="visible"
            app:elevation="5dp"
            app:labelVisibilityMode="labeled"
            app:itemTextAppearanceActive="@color/theme_color"
            app:itemBackground="@drawable/nav_item_background"
            app:itemIconTint="@drawable/tab_selected"
            app:itemTextColor="@drawable/tab_selected"
            app:menu="@menu/dashboard_menu"/>


    <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="@dimen/_40sdp"
            android:layout_height="@dimen/_40sdp"
            android:layout_marginBottom="@dimen/_60sdp"
            android:layout_marginEnd="@dimen/_24sdp"
            android:id="@+id/fbSettings"
            android:src="@drawable/theme_setting_img"
            android:layout_gravity="bottom|end"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:backgroundTint="@color/app_button" app:fabSize="normal"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

导航图

<?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/dashboard"
            app:startDestination="@id/icStudio">

    <fragment
            android:id="@+id/icStudio"
            android:name="com.augray.avmessage.ui.avatar.AvatarStudioFragment"
            android:label="AvatarStudioFragment"
            tools:layout="@layout/fragment_avatar_studio">
        <argument android:name="FilePath" app:argType="string" android:defaultValue='""'/>
        <argument android:name="scene_type" app:argType="string" android:defaultValue="studio_scene"/>
    </fragment>


    <fragment
            android:id="@+id/icARChat"
            android:name="com.augray.avmessage.ui.dashboard.fragments.archat.ARChatFragment"
            android:label="ARChatFragment"
            tools:layout="@layout/fragment_ar_chat">
    </fragment>


    <fragment android:id="@+id/icARWorld"
              android:name="com.augray.avmessage.ui.dashboard.fragments.arworld.ARWorldFragment"
              android:label="ARWorldFragment"
              tools:layout="@layout/fragmennt_ar_world">
    </fragment>

    <fragment android:id="@+id/icVRWorld"
              android:name="com.augray.avmessage.ui.dashboard.fragments.vrworld.VRWorldFragment"
              android:label="VRWorldFragment"
              tools:layout="@layout/fragment_vr_world"/>

    <fragment android:id="@+id/icProfile"
              android:name="com.augray.avmessage.ui.dashboard.fragments.profile.ProfileFragment"
              android:label="ProfileFragment"
              tools:layout="@layout/fragment_profile"/>

</navigation>

请帮助我,问题出在哪里,谢谢您

注意:已删除的图片

0 个答案:

没有答案