How to achieve ripple animation using support library?

Basic ripple setup

  • Ripples contained within the view.
    android:background="?selectableItemBackground"

  • Ripples that extend beyond the view’s bounds:
    android:background="?selectableItemBackgroundBorderless"

    Have a look here for resolving ?(attr) xml references in Java code.

Support Library

  • Using ?attr: (or the ? shorthand) instead of ?android:attr references the support library, so is available back to API 7.

Ripples with images/backgrounds

  • To have a image or background and overlaying ripple the easiest solution is to wrap the View in a FrameLayout with the ripple set with setForeground() or setBackground().

Honestly there is no clean way of doing this otherwise.

Leave a Comment