如何通过Jetpack导航和屏幕上的BottomNavigationView制作整个屏幕的深片段?

问题描述 投票:0回答:2

我研究了https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample处的google示例,它的工作方式如下:

enter image description here

enter image description here

但是我需要about片段来显示整个屏幕。最佳实践是什么?

我尝试过这个:activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.root_activity,Detail())?.addToBackStack("About")?.commit()

并获得此:

enter image description here

activity_main.xml:

<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:layout_width="match_parent"
android:id="@+id/root_activity"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.navigationadvancedsample.MainActivity">

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/nav_host_container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_nav"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:menu="@menu/bottom_nav"/>

我可以设置activity?.findViewById<BottomNavigationView>(R.id.bottom_nav)?.visibility=View.GONEactivity?.findViewById<BottomNavigationView>(R.id.bottom_nav)?.visibility=View.INVISIBLE但是当它回来时,看起来像这样,我认为这不是一个好方法:enter image description here

谢谢!

android android-fragments navigation-drawer bottomnavigationview android-jetpack
2个回答
0
投票

您必须切换BottomNavigationView的可见性,如下所示:


0
投票

如果有人有相同的问题,请在这里发布我的答案。

© www.soinside.com 2019 - 2024. All rights reserved.