Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android showing only drawable of TextView but not the Text

I’ve made a "menù" in my BottomSheetDialog the issue is that in the preview all is shown correctly but when i test if on a real device some of TextViews just does not shows the Text!

enter image description here

Here is the XML

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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>

While on a real device it’s shown as the following:

enter image description here

>Solution :

Some of your TextView tags are using the tools:text attribute:

<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"/>

The tools namespace is specifically designed to take effect in the Android Studio layout editor preview window, but be ignored when the app is actually run. This lets you put in placeholder values to make writing the XML easier, without affecting the app’s behavior.

Change these to android:text and the text will appear when you run the app.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading