【Android】Android 水波點選效果
阿新 • • 發佈:2019-02-20
由於Material Theme只可以在Android L Developer Preview中使用。 所以在低版本使用的話就需要為其另設一套主題: 在老版本使用一套主題 res/values/styles.xml,在新版本使用Material主題res/values-v21/styles.xml.
新增一個普通的 ripple_bg_drawable.xml 背景檔案
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape ="rectangle">
<solid android:color="#8cc476" />
<corners android:radius="0dp" />
</shape>
新增帶波紋效果的背景檔案 ripple_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF21272B">
<item android:drawable ="@drawable/ripple_bg_drawable" />
</ripple>
如果你的api最低版本低於21,則ripple這裡其實是有錯誤提醒的,低於這個版本會報錯。
android:background="?android:attr/selectableItemBackground"波紋有邊界
android:background="?android:attr/selectableItemBackgroundBorderless"波紋超出邊界