?android:attr/selectableItemBackground 在深色背景上不够明显

?android:attr/selectableItemBackground not visible enough on a dark background

在 Android Lollipop 上,我正在使用:

android:background="?android:attr/selectableItemBackground"

单击按钮时获得 material 动画反馈。

当我在 white/light 布局中包含一个按钮时效果很好,例如 CardView。

但是当我想在深色背景上使用同样的东西时,我们几乎看不到效果,它不够明显。

有人有想法吗?

谢谢

在 API 21+ 上,您可以在 ViewViewGroup 上设置 android:theme="@android:style/ThemeOverlay.Material.Dark" 以更改所有主题属性(文本颜色、波纹颜色、按钮颜色等)到 "dark" 版本。如果在 ViewGroup 上设置它,主题也会应用于 inflation 期间的所有子元素。这是在其他 "light" 界面(反之亦然)中拥有 "dark" 区域的简单方法。

<LinearLayout
    android:id="@id/my_dark_layout"
    ...
    android:theme="@android:style/ThemeOverlay.Material.Dark">

    <TextView
        android:id="@id/my_dark_bounded_ripple"
        ...
        android:background="?android:attr/selectableItemBackground"
        android:text="Bounded ripple" />

    <ImageButton
        android:id="@id/my_dark_unbounded_ripple"
        ...
        android:background="?android:attr/selectableItemBackgroundBorderless"
        android:src="@drawable/my_icon" />

</LinearLayout>

使用 AppCompat 的解决方案(也适用于旧 API)

android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
android:background="?attr/selectableItemBackground"

还有一种更改应用主题的方法:

Theme.AppCompat.NoActionBar

对我来说效果很好。