Home » Android » java – android background color xml tag not working in android studio-Exceptionshub

java – android background color xml tag not working in android studio-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

This Code is From a Tutorial on youtube https://youtu.be/rs10f5MsKEQ @ 4:48
in the video as soon as she types the color tag she gets a square in the preview but i dont and i wonder if someone know why, i have my android studio api level set the same as in the video Level 15

  <?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity"
    android:background="@drawable/bg">

    <TextView
        android:id="@+id/scoreLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Score : 0"
        android:textSize="18sp"
        android:textStyle="bold"
        android:paddingVertical="14dp"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:background="@android:color/white"/>

    <FrameLayout
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:layout_gravity="center_horizontal">

    </FrameLayout>

</
LinearLayout>

See image below:

see image

How to&Answers:

Try like this, LinearLayouts default orientation is horizontal, you need to define orientation as vertical. android:orientation="vertical"

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@drawable/bg">

    <TextView
        android:id="@+id/scoreLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Score : 0"
        android:textSize="18sp"
        android:textStyle="bold"
        android:paddingVertical="14dp"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:background="@android:color/white"/>

    <FrameLayout
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:layout_gravity="center_horizontal">

    </FrameLayout>

</
LinearLayout>