Lollipop RippleDrawable vs Selector for Pre-Lollipop

1) Yes. See the documentation for RippleDrawable for more details on how layers are composited, but basically you want:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item android:drawable="https://stackoverflow.com/questions/24607339/@drawable/yourninepatch" />
</ripple>

Or to also handle the disabled state in a clean way, you might want:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item>
        <selector>
            <item android:state_enabled="false">
                <nine-patch
                    android:src="https://stackoverflow.com/questions/24607339/@drawable/yourninepatch"
                    android:alpha="?android:attr/disabledAlpha" />
            </item>
            <item>
                <nine-patch android:src="https://stackoverflow.com/questions/24607339/@drawable/yourninepatch" />
            </item>
        </selector>
    </item>
</ripple>

2) Yes, you should place your ripple XML in drawable-v21.

Leave a Comment