所以我想使用工具列但是當我在樣式中將 DarkActionBar 更改為 NoActionBar 時,操作欄不會完全洗掉并且應用程式標題在我的工具列上。
https://i.stack.imgur.com/0X722.jpg
這是我的 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:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:id="@ id/myToolbar"
android:background="@color/design_default_color_primary_dark"
android:layout_height="?attr/actionBarSize">
<TextView
android:layout_width="wrap_content"
android:text="Toolbar"
android:textSize="22sp"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_height="wrap_content"
tools:ignore="HardcodedText" />
</androidx.appcompat.widget.Toolbar>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
我該怎么辦?對不起,英語不好順便說一句。
uj5u.com熱心網友回復:
我想你有這樣的 MainActivity 代碼,你得到了截圖所示的結果
setSupportActionBar(myToolbar)
只需洗掉此行或添加 app:title=" "標簽
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:id="@ id/myToolbar"
app:title=" "
android:background="@color/design_default_color_primary_dark"
android:layout_height="?attr/actionBarSize">
<TextView
android:layout_width="wrap_content"
android:text="Toolbar"
android:textSize="22sp"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_gravity="center"
android:layout_height="wrap_content"
tools:ignore="HardcodedText" />
</androidx.appcompat.widget.Toolbar>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/359602.html
