Question

I have declared colours in color.xml file but unfortunately unable to get those colours while setting the colour attribute to textview.

Color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="dark_snuff">#2d3037</color>  
   <color name="silver">#C0C0C0</color>
   <color name="dark_gray">#A9A9A9</color> 
</resources>

layout.xml

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:orientation="horizontal" >

            <TextView
            android:id="@+id/textView19"
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:text="Date"
            android:textAppearance="?android:attr/textAppearanceLarge" 
            android:background="@android:Color/dark_snuff"/>//error part

        </LinearLayout>

Error:

error: Error: No resource found that matches the given name (at 'background' with value '@android:Color/ dark_snuff').

Was it helpful?

Solution

Simply write @color/dark_snuff. That should do it!

EDIT as @Machinarius said, the prefix android refers to the namespace of Android's built-in colors, whereas you want colors from your own project. Also, in resource identifiers, everything must be lower case, so an uppercase Color wouldn't work, even if the resource you were trying to access existed in the appropriate namespace.

OTHER TIPS

@android:color/... is used to get a resource color from Android library. Whereas @color/... is used to get the resource color from the colors.xml file (with an "s" at the end and without caps) into the app.

android:background="@color/dark_snuff"  

should be the solution to get your own color items. However, if you want to use Android resources color, it's as follows:

android:background="@android:color/darker_gray"  

without caps. And you can find all of them in the Resources Documentation.

@android:Color/dark_snuff refers to the default built-in colors available in android. So plase use android:background="@color/dark_snuff" which WILL do the trick. 

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"

The first of all u should not save the file name with Caps (Capital letters) and if it is your application res folder which you are calling should be @color/dark_snuff not like @android:Color/dark_snuff

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top