[英]Add standard button animation to a TextView
创建波纹效果作为选择器 xml 文件:
波纹.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/gray" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@android:color/transparent" />
</shape>
</item>
</selector>
然后将其设置为视图的背景:
android:background="@drawable/ripple"
您可以编辑 xml 中的颜色和形状以匹配您想要的样式
如果您的目标是 API 23 或更高版本,您可以使用background
和foreground
属性的组合:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/orange"
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.