我正在尝试添加一个点击按钮的涟漪动画。我确实喜欢下面的,但它需要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" />
我想让它与设计库向后兼容。
如何做到这一点?
发布于 2018-03-24 02:22:59
有时你有一个自定义的背景,在这种情况下,更好的解决方案是使用android:foreground="?selectableItemBackground"
更新
如果你想要圆角和自定义背景的涟漪效果,你可以使用这个:
background_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/ripple_color">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:radius="5dp" />
</shape>
</item>
layout.xml
<Button
android:id="@+id/btn_play"
android:background="@drawable/background_ripple"
app:backgroundTint="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/play_now" />
我在API >= 21上使用了这个。
发布于 2018-06-15 16:44:35
有时在任何布局或组件上都能用到这一行。
android:background="?attr/selectableItemBackground"
就像as。
<RelativeLayout
android:id="@+id/relative_ticket_checkin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground">
https://stackoverflow.com/questions/26604134
复制相似问题