문제

I just tried this example. I saved that code in res/color/hover.xml but I always get this error message and Eclipse won't compile my project with this xml. What am I doing wrong?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector> <!-- Error Message -->

Error parsing XML: not well-formed (invalid token) hover.xml /MmAndroid/res/color line 8 Android AAPT Problem

The only thing I might not have done is following. I don't know how to do that:

compiled resource datatype: Resource pointer to a ColorStateList.

도움이 되었습니까?

해결책

you have to put this xml file inside the drawable folder. not in res/color

다른 팁

How stupid, that they have such major mistakes in their examples on android.com!

It's not a mistake at-all. You can define selectors for text or for backgrounds. Lets say you want your text to be green, if state_check="true". What will you do then? Lay a background behind?

No. You will probably create an xml file with selectors for color-attributes. And reference textColor="@color/MYNEWCOLORXML" .... ét voilà.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top