Matthew Whittenham Matthew Whittenham - 13 days ago 5
Java Question

How to set TextView text colour in Android Studio API 10

I am creating an Android API 10 app, and am trying to set the colour of text in TextViews. I wish to set the colour to red, but 'holo_red_dark', which is the colour I am using is only available for API 14 & above. I cannot find any colour red in the 'resources' window that is compatible with API 10, so I just wanted to know how I would get around this? Thanks.

Answer

You can create a colors.xml file in your res folder and define your colors.

Example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <item name="blue" type="color">#FF33B5E5</item>
</resources> 

And use it like

<TextView  
    android:layout_width="fill_parent" 
    android:text="@string/hello" 
    android:layout_height="wrap_content" 
    android:id="@+id/TextView01" 
    android:textColor="@colors/blue"/>

Check this: https://developer.android.com/samples/BasicMediaRouter/res/values/colors.html

Comments