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
Dark theme applies to both the Android system UI and apps running on the device. There are three ways to enable Dark theme in Android 10 (API level 29) and higher: Use the system setting (Settings -> Display -> Theme) to enable Dark theme. Use the Quick Settings tile to switch themes from the notification tray (once enabled).
Note that dark-themed android:windowBackground drawables only work on Android 10. When the app’s theme changes (either through the system setting or AppCompat) it triggers a uiMode configuration change.
?android:attr/selectableItemBackgroundBorderless for a ripple that extends beyond the view. It will be drawn upon, and bounded by, the nearest parent of the view with a non-null background. Note: selectableItemBackgroundBorderless is a new attribute introduced in API level 21.
Apps must opt-in to Force Dark by setting android:forceDarkAllowed="true" in the activity's theme. This attribute is set on all of the system and AndroidX provided light themes, such as Theme.Material.Light. When you use Force Dark, you should make sure to test your app thoroughly and exclude views as needed.
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>
Solution with AppCompat (works on old APIs too)
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
android:background="?attr/selectableItemBackground"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With