gpt4 book ai didi

android - 如何使用支持库实现波纹动画?

转载 作者:IT老高 更新时间:2023-10-28 12:55:11 26 4
gpt4 key购买 nike

我正在尝试在按钮单击时添加波纹动画。我确实喜欢下面,但它需要 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com