selectableItemBackgroundBorderless for textview

ⅰ亾dé卋堺 提交于 2021-02-06 20:29:25

问题


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?


回答1:


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.




回答2:


1.To limit the ripple effect inside the view only you need to specify

android:background="?attr/selectableItemBackground"

inside the view.

2.For making ripple effect border less i.e show ripple effect in whole layout you can use this.

android:background="?attr/selectableItemBackgroundBorderless"

3.For more you can check the link Defining Custom Animation



来源:https://stackoverflow.com/questions/30530893/selectableitembackgroundborderless-for-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!