Problem on android:background="@drawable/white"//

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Problem on android:background="@drawable/white"//

Postby johnsnowsyh » Mon Oct 19, 2009 9:45 am

Hi,

I am brand new to the android development, please help me with the following problem if you have any idea.

I built color.xml under the rec directory,

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<drawable name="darkgray">#808080FF </drawable>
<drawable name="white">#FFFFFFFF </drawable>
</resources>

however, in main.xml, the following line has error, telling that @drawable/white could not be found.

android:background="@drawable/white"

my main.xml is as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white" //this line has problem
>


Thank you.

Regards,
john
johnsnowsyh
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Oct 19, 2009 9:37 am

Top

Postby qlimax » Mon Oct 19, 2009 1:49 pm

hi :D

you have to put the color.xml (i.e) file in the res/values/ folder (the same as the string.xml file)

the the color.xml must be formatted like this (this is rgb but you can use argb as well)

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <resources>
  5.  
  6. <color name="red">#FF0000</color>
  7.  
  8. <color name="green">#00FF00</color>
  9.  
  10. </resources>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4



to use the color in a layout.xml (i.e) file
you have to do it like this


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. .....
  2.  
  3. <TextView
  4.  
  5. android:textSize="20px"
  6.  
  7. android:background="@color/green"
  8.  
  9. android:id="@+id/aTextView"
  10.  
  11. android:layout_width="wrap_content"
  12.  
  13. android:layout_height="wrap_content"
  14.  
  15. android:paddingBottom="5px"
  16.  
  17. android:textColor="@color/red">
  18.  
  19. </TextView>
  20.  
  21. ....
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


cya :run:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 9 guests