I want to set the background of a TextView object programmatically, but also have a ripple effect for it.
I can use with background set to android:selectableItemBackground
, but the ripple effect gets lost, when setting the background.
I also tried putting an ImageView
together with the TextView
in a FrameLayout
. And set the image not as the background of the TextView
, but as image of the ImageView
: Yes, ripple is there, but it appears to be "behind" the image.
Do I need to create a RippleDrawable
from the bitmapfor the background? How would I do that?
RippleDrawable is the solution:
I had same problem as you and fixed it using
android:foreground="?attr/selectableItemBackground"
on FrameLayout.Here is the sample FrameLayout: