我正在尝试在按钮单击时添加波纹动画。我确实喜欢下面,但它需要 minSdKVersion 到 21。
ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
按钮
<com.devspark.robototextview.widget.RobotoButton
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:text="@string/login_button" />
我想让它向后兼容设计库。
如何做到这一点?
最佳答案
基本波纹设置
View 中包含的涟漪。
android:background="?selectableItemBackground"
超出 View 边界的涟漪:
android:background="?selectableItemBackgroundBorderless"
看看here用于解析 Java 代码中的
?(attr)
xml 引用。
支持库
- 使用
?attr:
(或?
简写)而不是?android:attr
引用 support library ,因此可返回到 API 7。
带有图像/背景的涟漪
- 要拥有图像或背景并覆盖波纹,最简单的解决方案是将
View
包装在FrameLayout
中,并使用setForeground()
设置波纹code> 或setBackground()
.
老实说,否则没有干净的方法可以做到这一点。
关于android - 如何使用支持库实现波纹动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26604134/