我在我的 BottomSheetDialog 中制作了一個“menù”,問題是在預覽中所有內容都正確顯示,但是當我測驗是否在真實設備上某些 TextViews 只是不顯示Text!

這是XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:behavior_peekHeight="96dp">
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:text="Coca cola 330ml"
android:gravity="center_vertical"
android:textSize="18sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="8dp"
android:text="Quantità"
android:textSize="16sp"
app:drawableLeftCompat="@drawable/ic_baseline_calculate"
android:drawablePadding="16dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<ImageButton
android:id="@ id/meno"
android:background="@drawable/roundcorner"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="15dp"
android:layout_gravity="center"
app:srcCompat="@drawable/ic_baseline_remove_24"
android:contentDescription="Meno"
tools:ignore="HardcodedText" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:hintEnabled="false"
android:paddingEnd="15dp"
android:paddingStart="15dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:boxBackgroundMode="none"
app:boxStrokeWidthFocused="0dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/qta"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FFFFFF"
android:clickable="false"
android:focusable="false"
android:inputType="none"
android:text="1"
android:textAlignment="center"
android:textSize="16sp"
tools:ignore="HardcodedText,TouchTargetSizeCheck" />
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="@ id/piu"
android:background="@drawable/roundcorner"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
app:srcCompat="@drawable/ic_baseline_add_24"
android:contentDescription="Più"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/selectableItemBackground"
android:padding="8dp"
android:textSize="16sp"
tools:text="Variante libera"
android:gravity="center_vertical"
app:drawableLeftCompat="@drawable/ic_baseline_restaurant_24"
android:drawablePadding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/selectableItemBackground"
android:padding="8dp"
android:textSize="16sp"
tools:text="Variante libera"
android:gravity="center_vertical"
app:drawableLeftCompat="@drawable/ic_baseline_fastfood_24"
android:drawablePadding="16dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Stampa"
android:padding="8dp"
android:textSize="16sp"
app:drawableLeftCompat="@drawable/ic_baseline_print_24"
android:drawablePadding="16dp"/>
<CheckBox
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:checked="true"
android:gravity="center_vertical" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:padding="8dp"
android:textSize="16sp"
tools:text="Elimina"
android:gravity="center_vertical"
app:drawableLeftCompat="@drawable/ic_baseline_delete"
android:drawablePadding="16dp"/>
</LinearLayout>
在真實設備上顯示如下:

uj5u.com熱心網友回復:
您的一些 TextView 標記正在使用該tools:text屬性:
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:padding="8dp"
android:textSize="16sp"
tools:text="Elimina"
android:gravity="center_vertical"
app:drawableLeftCompat="@drawable/ic_baseline_delete"
android:drawablePadding="16dp"/>
命名空間專門設計用于在toolsAndroid Studio 布局編輯器預覽視窗中生效,但在應用實際運行時會被忽略。這使您可以輸入占位符值,以便更輕松地撰寫 XML,而不會影回應用程式的行為。
將這些更改為android:text,當您運行應用程式時,文本將出現。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464814.html
標籤:安卓
