开发者

Android: My XML with a selector is not well-formed while styling a button?

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à.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜