Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom selectableItemBackground

I'm using a RecyclerView for a list. I've a found a really nice solution to give the list click feedback and ripple (on Lollipop). Basically I'm giving my row layout the attribute:

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

And everything is fine, except that I need a different background color for my list (default state). How can I override just the basic state background (not clicked) giving it a different color?

like image 941
Jumpa Avatar asked Jun 29 '15 13:06

Jumpa


People also ask

What is selectableItemBackground?

selectableItemBackground is the name of an attribute in your app's theme (usually in styles. xml ). You might not be setting a value for it in your theme, but it might have a value in the parent theme that yours extends from, so your theme has that value as well.

What is ripple effect in Android?

The touch feedback in Android is a must whenever the user clicks on the item or button ripple effect when clicking on the same, gives confidence to the user that the button has been clicked so that they can wait for the next interaction of the app.


2 Answers

This will give custom background color and default grey ripple effect:

android:background="@color/YourCustomColor"
android:foreground="?android:attr/selectableItemBackground"
like image 117
Rupinder Singh Avatar answered Nov 13 '22 15:11

Rupinder Singh


You can try this: it helped me a lot, this way we can use the background we want and keep the great click feedback. Wrap your row view inside a frame layout.

like image 22
Andrés Felipe Guzmán Avatar answered Nov 13 '22 17:11

Andrés Felipe Guzmán