Android:在设置按钮样式时,带有选择器的 XML 格式不正确?
我刚刚尝试了这个示例。我将该代码保存在 res/color/hover.xml 中,但我总是收到此错误消息,并且 Eclipse 不会使用此 xml 编译我的项目。我做错了什么?
<?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 -->
解析 XML 时出错:格式不正确(无效令牌)hover.xml /MmAndroid/res/color line 8 Android AAPT 问题
我可能没有做的唯一一件事是以下。我不知道该怎么做:
编译资源数据类型:资源 指向 ColorStateList 的指针。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将此 xml 文件放入可绘制文件夹中。不是分辨率/颜色
you have to put this xml file inside the drawable folder. not in res/color
这根本不是一个错误。
您可以定义文本或背景的选择器。假设您希望文本为绿色(如果
state_check="true"
)。那你会做什么?后面有背景吗?不会。您可能会创建一个带有颜色属性选择器的 xml 文件。并参考
textColor="@color/MYNEWCOLORXML"
.... 瞧。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à.