Understanding the new features of Android 5.0---- water ripple

1. This article introduces one of the cool effects in Android 5.0. Click RippleEffect. The implementation methods described below are all calling the new API of Android 5.0, not a custom implementation, so it is supported in Android 5. .0 devices, and if you want to be compatible with lower system versions, you need to create a new v21 (ie Android5.0) Resource Directory. The

   effect is as follows: (ps: Since the emulator of the company's machine cannot run, it has to be copied online. The effect of others)

2, define a rounded_corners.xml with a normal rounded background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="4dp" />
</shape>

3. Create a ripple_bg.xml 
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#FF21272B">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="4dp" />
        </shape>
    </item>
    <item android:drawable="@drawable/rounded_corners" />
</ripple>

4. Fill in the following code directly on the control where you want to use this effect:
android:background="@drawable/ripple_bg"

Supplement: When you use the Material theme, the ripple animation will be automatically applied to all controls. Of course, we can set its properties to adjust to the effect we need. You can do this without using the above code, and add the following code directly to the control to achieve this effect:
android:background="?android:attr/selectableItemBackground" ripple has border
 
android:background="?android:attr/selectableItemBackgroundBorderless" ripples out of bounds

The effect is as follows (the first one is nothing written, the default is used):

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326655232&siteId=291194637
Recommended