首页 > 解决方案 > 将标准按钮动画添加到 TextView

问题描述

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

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

当我点击它时,会有一个流畅的标准动画。我怎样才能在 TextView 上做同样的事情?想象一下,我有一个橙色的 textView,其行为类似于 Button。如何向它添加相同的动画?太感谢了

标签: javaandroidxml

解决方案


如果您的目标是 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" />

推荐阅读