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):