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

狂风中的少年 提交于 2020-01-22 07:57:49

问题


On Android Lollipop, I'm using:

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

to have the material animated feedback when I click on a button.

It works well when I have a button contained in a white/light layout, like a CardView for example.

But when I want to use the same thing on a dark background, we barely see the effect, it is not visible enough.

Does someone have an idea?

Thank you


回答1:


On API 21+ you can set android:theme="@android:style/ThemeOverlay.Material.Dark" on a View or ViewGroup to change all of the theme attributes (text color, ripple color, button color, etc.) to the "dark" versions. If you set it on a ViewGroup, the theme is also applied to all of the child elements during inflation. It's an easy way to have regions of "dark" in an otherwise "light" interface (or vice versa).

<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>



回答2:


Solution with AppCompat (works on old APIs too)

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



回答3:


There is another way to change the app theme:

Theme.AppCompat.NoActionBar

It works fine for me.



来源:https://stackoverflow.com/questions/28605031/androidattr-selectableitembackground-not-visible-enough-on-a-dark-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!