I am trying to add a ripple animation on button click. I did like below but it requires minSdKVersion to 21.
ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
Button
<com.devspark.robototextview.widget.RobotoButton
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:text="@string/login_button" />
I want to make it backward compatible with the design library.
How this can be done?
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
?attr:
(or the ?
shorthand) instead of ?android:attr
references the support library, so is available back to API 7.Ripples with images/backgrounds
View
in a FrameLayout
with the ripple set with setForeground()
or setBackground()
.Honestly there is no clean way of doing this otherwise.