Android Build a Simple Android App Creating the Screen Layout Setting Colors

Change android background color

try to change the Android background color to darkpink with code fff092b0 I know I need to define darkpink somewhere, but don't know where. I read that you have to define it in strings.xml, but don't know the syntax.

<color name="darkpink">#FFF092B0</color> . . . android:background= "@android:color/darkpink"

activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 <color name="darkpink">#fff092b0</color>
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/darkpink"


  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Treehouse loves me!"
    android:textColor="@android:color/white"
    android:textSize="72sp" />

</RelativeLayout>
Jordan Ernst
Jordan Ernst
5,121 Points

also should mention that you don't need to change any of the code already written. just worry about the one line labeled "android:background= "" <<<<<<<< this is what you need to fix. nothing else

2 Answers

Jordan Ernst
Jordan Ernst
5,121 Points

hey friend technically you are right, but you are also wrong. you would have to add it to your xml <String> although it is just asking you to set the color by a default hex value. so no name is required. just #fff092b0 is needed! happy coding :)

Mazen Halawi
Mazen Halawi
7,806 Points

add a darkpink color in styles (resources -> values -> styles) <color name="darkpink">#fff092b0</color> then you can reference it in your layout xml