Ripple effect for lollipop views

白昼怎懂夜的黑 提交于 2019-12-02 19:06:54

You have to set your button's background to a RippleDrawable which you can define in XML. (I'll name it holo_blue_ripple.xml)

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/white"> <!-- ripple color -->

    <item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->

</ripple>

Then reference it with android:background="@drawable/holo_blue_ripple".

Try this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    ...
 />

Based on this tutorial and the official docs

Meanman

Also ?attr/selectableItemBackgroundBorderless canbe used for circular ripple effect.

Try this attribute

android:background="?attr/selectableItemBackground"

This is the simplest way to show ripple effect in your view/layout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!