Search code examples
androidstringtextdisplay

Button text not showing on the device


I'm currently following a course to learn android development but I encountered a problem:

I have set a textview and 4 button with text inside so that's okay, on android studio the text is displaying in the button but when I run the app on my device (Oukitel WP15 android 11 api 30) the button does not show any text so if anyone have a clue of what happening ? Thank you ! Code :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:padding="8dp">
    <TextView
        android:id="@+id/game_activity_textview_question"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="8dp"
        android:layout_weight="4"
        android:background="@color/teal_700"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="18sp"
        android:textStyle="bold"
        tools:text="@string/question" />

    <Button
        android:id="@+id/game_activity_button_1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:padding="16dp"
        android:textSize="20sp"
        tools:text="@string/answer1" />

    <Button
        android:id="@+id/game_activity_button_2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:padding="16dp"
        android:textSize="20sp"
        tools:text="@string/answer2" />

    <Button
        android:id="@+id/game_activity_button_3"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:padding="16dp"
        android:textSize="20sp"
        tools:text="@string/answer3" />

    <Button
        android:id="@+id/game_activity_button_4"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:padding="16dp"
        android:textSize="20sp"
        tools:text="@string/answer4" />
</LinearLayout>

Text not showing on my device

Text is showing on android studio


Solution

  • the tools: namespace is just for design, it doesn't do anything when the app is running.

    use android: instead:

    tools:text="@string/question"
    

    should be

    android:text="@string/question"