【问题标题】:Change Android CheckBox icon check/unchecked更改 Android CheckBox 图标选中/未选中
【发布时间】:2020-05-04 11:49:36
【问题描述】:

我是 Android 新手。我正在尝试更改 CheckBox 的图标。

这是我的代码,其中 star_checked 和 start_unchecked 是我的 drawable 中的 .png 文件。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="=@drawable/star_checked" android:state_checked="true"/>
    <item android:drawable="@drawable/star_unchecked" android:state_checked="false" />
</selector>

我收到以下错误: C:...\app\src\main\res\drawable\selector_priority.xml:3: AAPT: error: '=@drawable/star_checked' 与可绘制属性 (attr) 引用不兼容。

知道问题可能是什么吗?

提前致谢

【问题讨论】:

  • 去掉@drawable/star_checked之前的等号“=”
  • 非常感谢,它有效,我不敢相信我错过了这个错误。

标签: android checkbox icons


【解决方案1】:

由于语法错误,您在 android:drawable="=@drawable/star_checked" 这一行中使用了额外的等号。

使用此代码。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
    android:drawable="@drawable/star_checked" />
<item android:state_checked="false"
    android:drawable="@drawable/star_unchecked" />
</selector>

【讨论】:

    猜你喜欢
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 2012-06-17
    • 1970-01-01
    相关资源
    最近更新 更多