繁体   English   中英

将标准按钮 animation 添加到 TextView

[英]Add standard button animation to a TextView

如果它可能重复但找不到解决方案,我深表歉意。

看看这个橙色按钮在此处输入图像描述

当我点击它时,有一个平滑的标准 animation。 我怎样才能在 TextView 上做同样的事情? 想象一下,我有一个橙色的 textView,就像按钮一样。 如何添加相同的 animation 到它? 太感谢了

创建波纹效果作为选择器 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 或更高版本,您可以使用backgroundforeground属性的组合:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM