Storing hex color values in strings.xml Storing hex color values in strings.xml android android

Storing hex color values in strings.xml


You need to create a set of styles in your xml (regularly in res/values/styles.xml)

<color name="gray">#eaeaea</color><color name="titlebackgroundcolor">#00abd7</color><color name="titlecolor">#666666</color>

In the layout files you can call to the colors or styles:

android:textColor="@color/titlecolor"

Checkout some examples:

http://developer.android.com/guide/topics/ui/themes.html


You can declare explicit color resources. By convention these are placed in res/values/colors.xml:

<resources>    <color name="my_color">#FFFFFFFF</color></resources>

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:

<?xml version="1.0" encoding="utf-8"?><resources>   <color name="myColor">#000000</color></resources>

Then how do you refer this color value inside the application:

static:

android:textColor="@color/myColor"

Coding:

TextView1.setTextColor(R.color.myColor);