Custom selectableItemBackground

I am using RecyclerView for a list box. I found a really good solution to give feedback and click on the list (on Lollipop). Basically I give my row layout to 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 main background of the state (not clicked) by giving it a different color?

+3


source to share


3 answers


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



+1


source


This will give a custom background color and default gray ripple effect:



android:background="@color/YourCustomColor"
android:foreground="?android:attr/selectableItemBackground"

      

+1


source


Are you using CardViews

in RecyclerView

? If so, programmatically use .setCardBackgroundColor()

in holder

for each CardView

. Alternatively, you can wrap everything in a simple dummy FrameLayout

(with android: id) in CardView

and change that layout programmatically when you bind ViewHolders

.

0


source







All Articles