Android background line background

I am working on an XML layout file and I want to set the background color for LinearLayout. This bit that I am currently using works fine:

android:background="#1a64b7" 

However, I would rather break it. In my strings.xml file I have

 <string name="bg_blue">#1a64b7</string> 

but when I use it as follows:

 android:background="@string/bg_blue" 

it displays perfectly in the graphical representation of the layout in Eclipse, but the application crashes as soon as it opens. Any ideas? Thanks a ton.

Nick

+7
source share
3 answers

This is ... the right way to do it!

For example, you will need some xml resources with strings such as:

 <resources> <color name="candidate_normal">#FF000000</color> <color name="candidate_recommended">#FFE35900</color> <color name="candidate_other">#ff808080</color> <color name="candidate_background">#bbffffff</color> </resources> 
+10
source

It is best to keep your colors in color.xml and refer to them as "@ color / bg_blue". Save the strings.xml file for the language version only.

http://developer.android.com/guide/topics/resources/more-resources.html#Color

+1
source
0
source

All Articles