selectableItemBackgroundBorderless for textview

Vincent picture Vincent · May 29, 2015 · Viewed 17.6k times · Source

I have a TextView which is use as a button. I want to add attribute selectableItemBackgroundBorderless to have circle ripple effect when pressing. The layout is as following:

android:id="@+id/create_button"  
android:layout_width="wrap_content"
android:layout_height="54dp"
...
android:background="? android:attr/selectableItemBackgroundBorderless"

As a result, indeed the circle ripple effect when pressing, but the ripple goes out of the textview, but just out of the bottom of textview (because the top of the textview is action bar).

My question is, why ripple effect gets across the textview bottom? As you know, I have limited android:layout_height to 54dp. Why this limitation is useless?

Answer

Gaëtan picture Gaëtan · May 29, 2015

You have to use ?android:attr/selectableItemBackground to keep the ripple effect inside the View boundaries.

?android:attr/selectableItemBackgroundBorderless allows the effect to go outside of the View.