Ripple 的颜色应该是什么,colorPrimary 还是 colorAccent? (Material 设计)

What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)

我读过 Material Design Guidelines 但我不知道如果波纹不是黑色(带 alpha)应该是什么颜色。

例如,我有一个 colorPrimary = blue 和 colorAccent = red 的应用程序。实际上我使用的是 colorAccent(带 alpha),如果我想要黑色不同于波纹的颜色,我应该使用 colorPrimary(带 alpha)?

我检查了 Google 的所有应用程序,但他们从不使用带颜色的波纹。

像我现在这样的图片:

Widget.Material.Button style uses the btn_default_material.xml为背景:

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

请注意波纹颜色为 ?attr/colorControlHighlight,其中 by default is #40ffffff or #40000000 (for dark and light themes, respectively) as mentioned in the touch feedback guide

如您所见,波纹用于触摸反馈的微妙指示,因此默认情况下它们不使用 colorPrimarycolorAccent。这与 Android 4.4 (Kitkat) 中所做的更改一致,默认选择器颜色默认为中性。

这是 Roman Nurik 在推特上给我的回复:

Roman Nurik
@romannurik

@dahnark @romainguy it varies by situation, but rarely do you want to use the accent color. i'd say in general neutral or primary

对彩色波纹使用 26% 的 alpha。

Android L 不支持颜色状态列表中的主题属性,并且 <ripple> 元素没有 alpha 通道,但对于有界波纹,您可以执行以下操作:

<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 版本或使用颜色状态列表。这些中的任何一个都可以很好地产生无限的涟漪。

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/accent_26" />

res/values/colors.xml:

<resources>
    ...
    <color name="accent">#ff33b5e5</color>
    <color name="accent_alpha26">#4233b5e5</color>
</resources>

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>

这是您要查找的内容:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   ...
   <item name="colorControlHighlight">@color/ripple_material_dark</item>
   ...
</style>

作为参考,这些是 AppCompat 中定义的颜色。

<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>`