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

编程入门 行业动态 更新时间:2024-10-08 02:20:46
本文介绍了如何使用支持库实现波纹动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在单击按钮时添加波纹动画.我在下面确实喜欢,但是它要求minSdKVersion到21.

I am trying to add a ripple animation on button click. I did like below but it requires minSdKVersion to 21.

ripple.xml

ripple.xml

<ripple xmlns:android="schemas.android/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" />

我想使其与设计库向后兼容.

I want to make it backward compatible with the design library.

这怎么办?

推荐答案

基本波动设置

  • 该视图中包含的涟漪图. android:background="?selectableItemBackground"

  • Ripples contained within the view. android:background="?selectableItemBackground"

超出视图范围的波纹: android:background="?selectableItemBackgroundBorderless"

Ripples that extend beyond the view's bounds: android:background="?selectableItemBackgroundBorderless"

此处,用于解析Java代码中的?(attr) xml引用.

Have a look here for resolving ?(attr) xml references in Java code.

支持库

  • 使用?attr:(或?速记)代替?android:attr引用支持库,因此可用于API 7.
  • Using ?attr: (or the ? shorthand) instead of ?android:attr references the support library, so is available back to API 7.

带有图片/背景的波纹

  • 要获得图像或背景并叠加波纹,最简单的解决方案是将View包裹在FrameLayout中,并用setForeground()或setBackground()设置波纹.
  • To have a image or background and overlaying ripple the easiest solution is to wrap the View in a FrameLayout with the ripple set with setForeground() or setBackground().

老实说,否则没有干净的方法.

Honestly there is no clean way of doing this otherwise.

更多推荐

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

本文发布于:2023-08-03 06:35:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:波纹   如何使用   动画

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!