问题描述
Android 上最新版本的 YouTube 应用显示出非常不同的涟漪。
即当我们将手指从按钮上抬起时,在结束波纹时显示笔划。
如何在android中实现这种波纹?
解决方法
它实际上只是通过设置android:background="?selectableItemBackground"
在 Youtube 按钮示例中,
<RelativeLayout
android:id="@+id/rl_chat_search"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground" <-- ripple effect
android:layout_margin="10dp">
<ImageView
android:src="@drawable/ic_download"
/>
<TextView
android:text="Download"
/>
</RelativeLayout>
,
在您的点击视图中添加以下两个属性。
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"