Reputation: 25028
I have few TextView
s that are displayed beside each other. Currently, I use android:background="?attr/selectableItemBackground"
to get the ripple on touch.
Now, I would like to add borders to the TextView
s when they are not pressed and have the ripple when the TextView
is touched. How do I do that?
Upvotes: 10
Views: 4626
Reputation: 25028
Based on a Styling Android
blog post:
Another way that we can confine the bounds of a ripple animation is to actually define a shape drawable as a child
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke
android:color="@color/card_set_bg_color"
android:width="1dp" />
</shape>
</item>
</ripple>
Here the <solid>
in <shape>
is needed for the ripple to render. If set to transparent
or omitted, the ripple doesn't render. The ripple needs a solid background to render on. TextView
s don't have a background color so we need to specify a <solid>
.
Upvotes: 20