1. 程式人生 > >基於安卓5.0水波紋效果製作及自定義水波紋顏色

基於安卓5.0水波紋效果製作及自定義水波紋顏色

安卓5.0以後很多ui效果的改進都是為提高使用者體驗,其中水波紋效果是5.0以後是在互動方式中做的特殊處理
接下來學習一下水波紋的簡單使用及水波紋顏色的自定義。 首先佈局檔案中給控制元件設定為可點選,及背景的新增 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:background="?android:attr/selectableItemBackgroundBorderless"//此背景為安卓中預設顏色
android:clickable="true" android:text="預設水波紋顏色:無邊界效果"/><TextView android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:background="?android:attr/selectableItemBackground"
//此背景為安卓中預設顏色
android:clickable="true" android:gravity="center" android:text="預設水波紋顏色:無界效果"/><TextView android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:background="@drawable/ripple_item_background_normal" android:clickable="true" android:gravity="center" android:text="自定義水波紋顏色:無邊界效果"/><TextView android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:background="@drawable/ripple_item_background_select" android:clickable="true" android:gravity="center" android:text="自定義水波紋顏色:有邊界效果"/></LinearLayout> ripple_item_background_normal.xml檔案的定義
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorAccent"/> ripple_item_background_select.xml檔案的定義
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorAccent"><item android:drawable="@color/colorPrimary"/></ripple> 通過2種情況的xml檔案會發現在定義drawable為控制元件的背景顏色,在沒有定義的情況下為預設無邊界效果