我研究了https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample处的google示例,它的工作方式如下:
但是我需要about片段来显示整个屏幕。最佳实践是什么?
我尝试过这个:activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.root_activity,Detail())?.addToBackStack("About")?.commit()
并获得此:
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.GONE
或activity?.findViewById<BottomNavigationView>(R.id.bottom_nav)?.visibility=View.INVISIBLE
但是当它回来时,看起来像这样,我认为这不是一个好方法:
谢谢!
您必须切换BottomNavigationView的可见性,如下所示:
如果有人有相同的问题,请在这里发布我的答案。