【问题标题】:ImageButton set src as StateListDrawableImageButton 将 src 设置为 StateListDrawable
【发布时间】:2014-11-05 16:35:12
【问题描述】:

我正在尝试创建一个 ImageButton 来根据它是否启用来更改它的图标。我创建了以下文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icn_increase_inactive" />
    <item android:state_enabled="true" android:drawable="@drawable/icn_increase_active" />
</selector>

在启用和禁用之间切换状态时,没有任何变化。我还尝试创建自己的 ImageButton 来扩展 ImageButton 并尝试手动切换状态,但在 ImageButton 中,它将可绘制对象加载为 BitmapDrawable 而不是 StateListDrawable。在图像按钮之外加载时,它可以作为 StateListDrawable 工作。有什么想法吗?

【问题讨论】:

  • 你试过&lt;item android:state_enabled="false" android:drawable="@drawable/icn_increase_inactive" /&gt;

标签: android android-imagebutton


【解决方案1】:

在为此挣扎了这么久之后,我无法相信这一点。我需要做的就是交换物品。默认状态应该总是在底部。希望这可以节省其他人很多时间

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 2016-07-09
    相关资源
    最近更新 更多