android - Material design 3 波纹不透明度

标签 android material-design material-components-android

目前,MD3 使用我认为指定波纹颜色的 50% 的不透明度/alpha 来表示它们在组件上的按下状态。有什么办法可以改变它的不透明度吗?
这是我目前用来测试 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-beta01 Material 版。

最佳答案

我真的不认为你可以改变波纹颜色的不透明度,因为它是由框架决定的。它由 RippleDrawable 处理 Lollipop 及以上设备的类别和RippleDrawableCompat Lollipop 前设备的类。

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”。但是我不建议这样做。

关于android - Material design 3 波纹不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70397607/

相关文章:

android - 如何显示离散 slider 的刻度线?

android - 无法让 Android 电子市场排除此应用程序的小屏幕手机

android - Bottom Sheet 全屏显示

android - 使用 Material ExposedDropdownMenu 时出现样式错误

dart - Flutter Drawer 作为单独的小部件不允许修改宽度

android - 如何在自定义文本输入布局中修复背景红色

android - CustomDialog Android 中的 VideoView

java - Android Studio : failed to complete gradle execution, 原因为空

android - 如何在针对他们运行自动化测试时检测 android 中的应用程序崩溃?

android - 如何在 MaterialDatePicker 中禁用过去的日期?