I'm trying to store the hex color
value of my text in strings.xml so all the layout files will refer to that (to be able to quickly change all layout text for the project easily) however I'm having trouble referring to it.
Using android:textColor="#FFFFFF"
in my xml layout works fine. However using android:textColor="@strings/textColor"
gives me an error both when I include a # and not include.
When I don't include the # it asks for the #. When I do add the # DDMS reports:
07-13 04:35:22.870: ERROR/AndroidRuntime(331): Caused by: android.content.res.Resources$NotFoundException: File #FF0000 from drawable resource ID #0x7f040003: .xml extension required
Does anyone know how I can combine statements in the layout file? eg textColor="#"+"@strings/textColor
and then just set the string to "FFFFFF"
for example.
You can declare explicit color resources. By convention these are placed in res/values/colors.xml:
Then in layouts or elsewhere you can write
android:textColor="@color/my_color"
For that you can do one thing: Define colors.xml inside the values folder and then add your color value with # as given below:
Then how do you refer this color value inside the application:
static:
Coding:
Use these Colors
### your code is in string.xml file ###
In your code you are declare color name is "textColor" , I want to confirm you that the name given by text color is in-built method,but you can't override in-built method .
solution of your problem is , your code should like that :
in this case name of color is not inbuilt method and you have not facing any run time error.
thanks.
You need to create a set of styles in your xml (regularly in res/values/styles.xml)
In the layout files you can call to the colors or styles:
Checkout some examples:
http://developer.android.com/guide/topics/ui/themes.html