Material设计3波纹不透明度

Material design 3 ripple opacity

目前,MD3 使用 opacity/alpha,我认为 50% 的指定波纹颜色用于组件的按下状态。有什么办法可以改变它的不透明度吗?

这是我目前用来测试 MD3 中 material 按钮的连锁反应的方法:

<style name="Widget.App.Button" parent="Widget.Material3.Button">
    <item name="rippleColor">@color/black_000</item>
    <item name="android:textColor">@color/button_filled_foreground_color</item>
    <item name="backgroundTint">@color/white_1000</item>
</style>

按钮:

<Button
    style="@style/Widget.App.Button"
    android:id="@+id/create_account_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/create_account"
    app:layout_constraintBottom_toTopOf="@id/log_in_button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

在此示例中,背景颜色为白色,涟漪效果为灰色。如何将波纹不透明度更改为 100%,从而使波纹效果变为黑色?我用的是1.5.0-beta01material版本

我真的不认为你可以改变波纹颜色的不透明度,因为它是由框架决定的。对于棒棒糖前设备,它由 RippleDrawable class for devices with lollipop and above and RippleDrawableCompat class 处理。

Ripple opacity will be determined by the Android framework when available. Otherwise, this color will be overlaid on the button at a 50% opacity when button is pressed.

来自 MaterialButton 文档。

如果你真的想要纯黑色波纹,你可以尝试创建一个带有选择器标签的自定义可绘制对象,并将其设置为按钮中的背景,并将 backgroundTint 设置为“null”。但是我不建议这样做。