3

I'm a newcomer in android development. Have no idea what's wrong with this. The color that I have been declared in colors.xml value res can't not be used in my styles.xml...

here is how I declared the color in colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="my_green">#59ab1b</color>
    <color name="app_bgcolor">#ededed</color>
    <color name="txt_grey">#707070</color>
</resources>

then when i try to put use it in my style xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="lbl_welcome">
        <item name="android:textSize">17sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/my_green"</item>
    </style>
</resources>

it's said like this:

error: Error: No resource found that matches the given name (at 'android:textColor' with value '@color/ my_green"').

any idea?

thanks before!

4
  • make sure the styles.xml is in Project>>res>>values>>style.xml
    – Samuel
    Aug 5, 2011 at 4:39
  • i have put well the styles.xml in project>>res>values
    – richardlin
    Aug 5, 2011 at 4:45
  • 1
    yes, i will definitely accept the answers that helps and works.. :)
    – richardlin
    Aug 5, 2011 at 4:51
  • 1
    really sorry.. what a shame! it was just because a typo in my code.. if you noticed, i shouldn't have a quotation mark there... thanks Sam anyway.. i still up vote your answer though, because it's a new knowledge for me.. sorry again..
    – richardlin
    Aug 5, 2011 at 7:26

4 Answers 4

5

Hey I just noticed your item tag has a quote mark in the end, like this:

<item name="android:textColor">@color/my_green"</item>

and it should read like this:

<item name="android:textColor">@color/my_green</item>

without the " after my_green.

At least this way it works for me. Hope it helps!

1
  • hehe, I just had the EXACT same issue. (not very careful cutting and pasting from the Views XML that used to have it on my part)
    – darkflame
    May 16, 2014 at 12:55
1

can you try this and tell me if it works

<resources>
    <color name="my_green">#ff59ab1b</color>
    <color name="app_bgcolor">#ffededed</color>
    <color name="txt_grey">#ff707070</color>
</resources>
4
  • it makes the error in styles.xml disappear.. but, more error comes in my layout file, main.xml.. where i also you used the color.. weird?!
    – richardlin
    Aug 5, 2011 at 4:47
  • 1
    the prefix ff is the alpha of the color. if you give somethin like #4059ab1b you will have a translusent effect. so may be you editor is insisting on this format.
    – Samuel
    Aug 5, 2011 at 4:53
  • could you be more clear, in fact if you don't give it by default, it assumed as 'ff'
    – Samuel
    Aug 5, 2011 at 5:02
  • sorry just came back from lunch here i mean, when i try your advice to put the prefix ff the error in my styles.xml disappear, but it give some others error in my xml layout file, in which i also use the color as some of my layout and widget attribute.. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/my_green" > <Button android:id="@+id/btn_preRegister" android:text="@string/btn_preRegister" android:textColor="@color/my_green" />
    – richardlin
    Aug 5, 2011 at 6:29
0

Make sure both file are in the 'values' folder within 'res'

0
-1

use @android:color/your_color

eg. <item name="android:textColor">@android:color/my_green</item>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.