Android:在设置按钮样式时,带有选择器的 XML 格式不正确?

发布于 2024-09-23 23:51:50 字数 909 浏览 2 评论 0原文

我刚刚尝试了这个示例。我将该代码保存在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光瘦了 2024-09-30 23:51:50

您必须将此 xml 文件放入可绘制文件夹中。不是分辨率/颜色

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

七禾 2024-09-30 23:51:50

多么愚蠢,他们的例子中有如此重大的错误
android.com!

这根本不是一个错误。
您可以定义文本或背景的选择器。假设您希望文本为绿色(如果state_check="true")。那你会做什么?后面有背景吗?

不会。您可能会创建一个带有颜色属性选择器的 xml 文件。并参考 textColor="@color/MYNEWCOLORXML" .... 瞧。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文