问题描述
我已阅读材料设计指南,但我没有如果不是黑色(带有 alpha),不知道 Ripple 的颜色应该是什么.
I have reading Material Design Guidelines but I don't know what should be the color of the Ripple if it isn't black (with alpha).
例如,我有一个应用程序,colorPrimary = blue,colorAccent = red.实际上我正在使用 colorAccent(带 alpha),如果我想要一种不同于黑色到波纹的颜色,我应该使用 colorPrimary(带 alpha)?
For example, I have an app with colorPrimary = blue, and colorAccent = red. Actually I am using the colorAccent (with alpha), I should use colorPrimary (with alpha) if I want a color different of black to the ripple?
我检查了谷歌的所有应用,但他们从不使用带有颜色的涟漪.
I checked all app of Google but they never use ripples with color.
像我现在这样的图像:
推荐答案
对彩色波纹使用 26% alpha.
Use 26% alpha for colored ripples.
Android L 不支持颜色状态列表中的主题属性,并且 <ripple>
元素没有 alpha 通道,但对于有界涟漪,您可以执行以下操作:
Android L doesn't support theme attributes in color state lists and the <ripple>
element doesn't have an alpha channel, but for bounded ripples you can do something like:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorAccent">
<item android:id="@android:id/mask">
<color android:color="#42ffffff" />
</item>
</ripple>
这不适用于无限涟漪.或者,由于您知道自己的强调色,您可以定义 26% alpha 版本或使用颜色状态列表.对于无限的涟漪,这两种方法都可以正常工作.
This won't work for an unbounded ripple. Alternatively, since you know your own accent color, you can either define a 26% alpha version or use a color state list. Either of these will work fine for an unbounded ripple.
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/accent_26" />
res/values/colors.xml:
res/values/colors.xml:
<resources>
...
<color name="accent">#ff33b5e5</color>
<color name="accent_alpha26">#4233b5e5</color>
</resources>
res/color/accent_alpha26.xml:
res/color/accent_alpha26.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/accent"
android:alpha="0.26" />
</selector>
这篇关于Ripple、colorPrimary 或 colorAccent 的颜色应该是什么?(材料设计)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!