gpt4 book ai didi

android - Lollipop RippleDrawable 与 Pre-Lollipop 的选择器

转载 作者:IT王子 更新时间:2023-10-29 00:05:51 28 4
gpt4 key购买 nike

我有不同 draw9patch png 作为背景的按钮。目前按钮由 selector 控制,看起来像这样:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/disabled" android:state_enabled="false"/>
<item android:drawable="@drawable/focused" android:state_focused="true"/>
<item android:drawable="@drawable/default"/>
</selector>

对于 Android Lollipop,他们有一个用于触摸效果的 RippleDrawable,如下所示:

<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">
<item>
...
</item>
</ripple>

关于新的触摸涟漪效果:

1:我可以将draw9patch设置为RippleDrawable的背景吗?

2:我要如何适应上述两种不同的xml我想遵循Material design?我是否必须为新的 RippleDrawable 创建一个新的文件夹/布局 xml?

最佳答案

1) 是的。有关如何合成图层的更多详细信息,请参阅 RippleDrawable 的文档,但基本上你想要:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:drawable="@drawable/yourninepatch" />
</ripple>

或者也以干净的方式处理禁用状态,您可能想要:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item>
<selector>
<item android:state_enabled="false">
<nine-patch
android:src="@drawable/yourninepatch"
android:alpha="?android:attr/disabledAlpha" />
</item>
<item>
<nine-patch android:src="@drawable/yourninepatch" />
</item>
</selector>
</item>
</ripple>

2) 是的,您应该将您的波纹 XML 放在 drawable-v21 中。

关于android - Lollipop RippleDrawable 与 Pre-Lollipop 的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24607339/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com