我试图仅在某些片段中显示ActionBar:
override fun onResume() {
super.onResume()
(requireActivity() as AppCompatActivity).supportActionBar?.show()
}
override fun onPause() {
super.onPause()
(requireActivity() as AppCompatActivity).supportActionBar?.hide()
}
但是由于某种原因,每次我将其隐藏在底部导航栏“跳转”中
MainActivity.xml的代码:
<?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"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@drawable/selector"
app:itemTextColor="@drawable/selector"
app:menu="@menu/bottom_nav_menu" />
</LinearLayout>
NoActionBar
主题,例如您的活动为Theme.MaterialComponents.Light.NoActionBar
。