棒棒堂RippleDrawable VS选择为pre-棒棒糖 [英] Lollipop RippleDrawable vs Selector for Pre-Lollipop
问题描述
我有不同的draw9patch png格式
为背景的按钮。目前,该按钮被控制选择
这看起来是这样的:
I have buttons with different draw9patch png
as background. Currently the buttons are controlled by selector
which look something like this:
<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的棒棒堂他们有一个 RippleDrawable
的触摸效果,它是这样的:
For the Android Lollipop they have a RippleDrawable
for the touch effect, which goes something like this:
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">
<item>
...
</item>
</ripple>
关于新的触摸连锁反应:
Regarding the new touch ripple effect:
1:我可以设置draw9patch为背景 RippleDrawable
1: Can I set draw9patch as background for RippleDrawable
?
2 如何适应上述两个不同的XML的我想跟进材料的设计?我必须花上一个新的文件夹/ XML布局为新 RippleDrawable
?
2: How do I accomodate the above two different xml's I want to follow Material design? Do I have to fork out a new folder/layout xml for the new RippleDrawable
?
推荐答案
1)是的。请参阅如何层合成为RippleDrawable的文档以获得更多细节,但基本上你想要的:
1) Yes. See the documentation for RippleDrawable for more details on how layers are composited, but basically you want:
<?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>
或者也处理在清洁的方式禁用状态,您可能希望:
Or to also handle the disabled state in a clean way, you might want:
<?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)是的,你应该把在绘制-V21的波动XML。
2) Yes, you should place your ripple XML in drawable-v21.
这篇关于棒棒堂RippleDrawable VS选择为pre-棒棒糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!