I am working on a layout XML file, and I want to set a background color for a LinearLayout. This bit, which I am now using, works perfectly:
android:background="#1a64b7"
However, I would much prefer to break that out. In my strings.xml file I have
<string name="bg_blue">#1a64b7</string>
but when I use that in the following manner:
android:background="@string/bg_blue"
it shows up great in the Graphical Layout Preview in Eclipse, but the app crashes as soon as it opens. Any ideas? Thanks a ton.
Nick
This is the right way to do it!
For example you need some resources xml with lines like:
<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>
It is best practise to keep your colors defined in colors.xml, and reference them as "@color/bg_blue". Keep your strings.xml for language copy only.
http://developer.android.com/guide/topics/resources/more-resources.html#Color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With