【问题标题】:Material design 3 ripple opacityMaterial design 3 波纹不透明度
【发布时间】:2022-01-20 15:23:24
【问题描述】:

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

这是我目前用来测试MD3中材质按钮的波纹效果的:

<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材质版。

【问题讨论】:

  • 您能否添加代码示例,以便人们可以帮助您参考?
  • 我认为即使有代码也是不可能的。因此,您可能需要创建一个自定义波纹可绘制类。默认 alpha 设置为 0.5f 。检查类RippleBackground的来源。

标签: android material-design material-components-android


【解决方案1】:

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

Ripple 不透明度将由 Android 框架在可用时确定。否则,当按下按钮时,此颜色将以 50% 的不透明度覆盖在按钮上。

来自MaterialButton 文档。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 2017-07-01
    • 1970-01-01
    • 2015-06-26
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多