Ripple effect for lollipop views

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

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

  • Android: How to implement Parcelable to my objects?
  • Android fetch all contact list (name, email, phone) takes more then a minute for about 700 contacts
  • Android: Toggle Accelerometer Rotation State Setting
  • creating background drawable using layer-list, icon getting stretched
  • How to keep android from inverting the image from the front facing camera?
  • IabHelper class not working?
  • I found some third party libraries for the ripple effect, but I want to do this with standard API.

    This answer didn’t help either.

    XML:

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_below="@+id/textView"
        android:background="@android:color/holo_blue_bright"
        android:layout_alignParentStart="true"
        android:layout_marginTop="76dp"
       />
    

    Related posts:

    How to fall back to marketplace when Android custom URL scheme not handled?
    Android scroll up hide view and scroll down show view effect like twitter
    PhoneGap Build Push Notification (Android)
    Disable Android resource / image / png optimization
    Change Android 5.0 Actionbar color
    Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?
  • Android Google Places autocomplete api bounds not working
  • Are asserts available on Android?
  • Set a menu item as checked from code
  • Items of recyclerview confused
  • Using OpenGL from the main thread on Android
  • How To Set Text In An EditText
  • 4 Solutions collect form web for “Ripple effect for lollipop views”

    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

    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.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.