How to change background color in Android application?

Why android:background doesn't work for me?

  • my layout file as bellow <?xml version="1.0" encoding="UTF-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    tools:context=".LimeText" >        <TextView        android:id="@+id/file_title"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        ***android:background="@color/red"***         android:text="@string/untitled" />    <ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"            android:id="@+id/scroll"            android:orientation="vertical"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:fadingEdge="none">            <EditText        xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@+id/file_content"        ***android:background="@android:color/white"***                 android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:padding="5dip"                android:fadingEdge="none"                android:scrollbars="vertical|horizontal"                android:gravity="top"                android:autoText="false"                android:capitalize="none"             />    </ScrollView></LinearLayout> but no matter how do I change the background, the EditText's background always stay on black and the 'TextView's background always be grey. the grey TextView is set before, #CCCCCC, but now I want to change it to another color, it cannot.

  • Answer:

    If you are using this format to set color, make sure that you add relevant values to strings.xml file also.  But I'll suggest using the below mentioned format as you dont need to do anything else then: android:background="@android:color/red" The color resource is offered by android framework itself and this is the best way to use android provided resources in the layouts of your apps.

Akash Verma at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.