Ripple effect for lollipop views

前端 未结 4 367
有刺的猬
有刺的猬 2021-02-01 19:28

I have been developing an app for Lollipop (API 21).

When I change the Button color to something, the ripple effect doesn\'t works.

I found some t

相关标签:
4条回答
  • 2021-02-01 20:05

    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

    0 讨论(0)
  • 2021-02-01 20:16

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

    0 讨论(0)
  • 2021-02-01 20:17

    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".

    0 讨论(0)
  • 2021-02-01 20:24

    Try this attribute

    android:background="?attr/selectableItemBackground"
    

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

    0 讨论(0)
提交回复
热议问题