我有兩個片段。當我從第一個片段切換到第二個片段時,工具列上會顯示一個后退箭頭。如何使主螢屏上沒有空白而不是后退箭頭,但還有另一個按鈕?
工具列:
<androidx.appcompat.widget.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="64dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
兩個螢屏: 
uj5u.com熱心網友回復:
我通過添加自己的按鈕解決了這個問題。
<ImageButton
android:id="@ id/button_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/actionBarItemBackground"
app:srcCompat="@drawable/ic_settings" />
請注意,通過指定android:background="?attr/actionBarItemBackground"您可以獲得與常規工具列按鈕相同的點擊效果。
如果要在某些螢屏上隱藏按鈕,請將addOnDestinationChangedListener添加到NavController:
navController.addOnDestinationChangedListener { _, destination, _ ->
binding.buttonSettings.visibility =
if (destination.id == R.id.account_add_fragment) View.GONE else View.VISIBLE
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/369502.html
標籤:安卓 科特林 android-fragments 导航 工具栏
