我试图在单击按钮时添加波纹动画.我在下面确实喜欢,但是它要求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.
更多推荐
如何使用支持库实现波纹动画?
发布评论