【问题标题】:ImageButton is missing when drawable-v21 is added添加 drawable-v21 时缺少 ImageButton
【发布时间】:2016-01-16 01:10:53
【问题描述】:

为了包含我的 ImageButton 的涟漪效果,我在 res 中创建了 drawable-v21 文件夹并添加了以下代码

ans_go_btn.xml :-

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#c20586">
        <item>
            <shape android:shape="oval">
                <solid android:color="#fa09ad"/>
            </shape>
        </item>
    </ripple>
</selector>

drawable 目录中我有以下代码。

ans_go_btn.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape android:shape="oval"  >
            <solid android:color="@color/black"></solid>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="oval"  >
            <solid android:color="@color/light_blue"></solid>
        </shape>
    </item>
    <item >
        <shape android:shape="oval"  >
            <solid android:color="@color/blue_app"></solid>
        </shape>
    </item>
</selector>

图片按钮有android:background="@drawable/ans_go_btn"属性。

在 kitkat 设备中会出现 ImageButton,但在我的 Lollipop 设备中却没有。 我可能会犯一些明显的错误,但我无法找到它。 请帮忙!

谢谢

【问题讨论】:

标签: android android-drawable rippledrawable


【解决方案1】:

首先drawable-v21中的ans_go_btn应该是:

<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <ripple
            android:color="#c20586">
            <item>
                <shape android:shape="oval">
                    <solid android:color="#fa09ad"/>
                </shape>
            </item>
        </ripple>
    </item>
</selector>

选择器应该有项目,而不是波纹。

然后,您可以更改项目的属性。

【讨论】:

  • 哦,是的。你说的对。我添加并检查了它。现在我得到了图像和波纹。但是你能告诉我如何从 drawable 目录继承常见的状态相关颜色吗?谢谢:)
  • 继承普通状态?你的意思是添加诸如&lt;item android:state_pressed="true" &gt;之类的项目,只需在作为childof选择器的项目中添加state属性即可。
  • 是的。我已经将它们放在 drawable 文件夹中,文件名与所示相同。我的疑问是,我需要在'drawable-v21'中再次编写它们还是有其他方式?
  • 哦,你应该在'drawable-v21'中再写一遍,'drawable'和'drawable-v21'之间没有继承关系。它是为不同版本设计的。
猜你喜欢
  • 2016-02-06
  • 2021-03-16
  • 1970-01-01
  • 2017-05-29
  • 2021-06-03
  • 1970-01-01
  • 2018-10-01
  • 2019-11-11
  • 1970-01-01
相关资源
最近更新 更多