在衆多新晉庫中,MaterialDesignLibrary可以說是頗受開發者矚目的一個控件效果庫,能夠讓開發者在Android 2.2系統上使用Android 5.0才支持的控件效果,比如扁平、矩形、浮動按鈕,複選框以及各式各樣的進度指示器等。
除上述之外,MaterialDesignLibrary還擁有SnackBar、Dialog、Color selector組件,可非常便捷地對應用界面進行設置。
進度指示器樣式效果設置:
- <com.gc.materialdesign.views.ProgressBarCircularIndetermininate
- android:id="@+id/progressBarCircularIndetermininate"
- android:layout_width="32dp"
- android:layout_height="32dp"
- android:background="#1E88E5" />
- Dialog dialog = new Dialog(Context context,String title, String message);
- dialog.show();
相關鏈接:MaterialDesignLibrary的mobilehub主頁
2. RippleEffect
由來自法蘭西的Robin Chutaux開發的RippleEffect基於MIT許可協議開源,能夠在Android API 9+上實現Material Design,爲開發者提供了一種極爲簡易的方式來創建帶有可擴展視圖的header視圖,並且允許最大程度上的自定製。
用法(在XML文件中聲明一個RippleView):
- <com.andexert.library.RippleView
- android:id="@+id/more"
- android:layout_width="?android:actionBarSize"
- android:layout_height="?android:actionBarSize"
- android:layout_toLeftOf="@+id/more2"
- android:layout_margin="5dp"
- ripple:rv_centered="true">
- <ImageView
- android:layout_width="?android:actionBarSize"
- android:layout_height="?android:actionBarSize"
- android:src="@android:drawable/ic_menu_edit"
- android:layout_centerInParent="true"
- android:padding="10dp"
- android:background="@android:color/holo_blue_dark"/>
- </com.andexert.library.RippleView>
隨着Material Design的到來,AppCompat v21也爲開發者提供了Material Design的控件外觀支持,其中就包括EditText,但卻並不好用,沒有設置顏色的API,也沒有任何Google Material Design Spec中提到的特性。於是,來自國內的開發者“扔物線”開發了MaterialEditText庫,直接繼承EditText,無需修改Java文件即能實現自定義控件顏色。
自定義Base Color:
- app:baseColor="#0056d3"
自定義Error Color:
- app:maxCharacters="10"
- app:errorColor="#ddaa00"
相關鏈接:MaterialEditText的mobilehub主頁
Android-LollipopShowcase是由來自奧地利的移動、後端及Web開發者Mike Penz所開發的演示應用,集中演示了新Material Design中所有的UI效果,以及Android Lollipop中其他非常酷炫的特性元素,比如Toolbar、RecyclerView、ActionBarDrawerToggle、Floating Action Button(FAB)、Android Compat Theme等。
相關鏈接:Android-LollipopShowcase的mobilehub主頁
5. MaterialList
MaterialList是一個能夠幫助所有Android開發者獲取谷歌UI設計規範中新增的CardView(卡片視圖)的開源庫,支持Android 2.3+系統。作爲ListView的擴展,MaterialList可以接收、存儲卡片列表,並根據它們的Android風格和設計模式進行展示。此外,開發者還可以創建專屬於自己的卡片佈局,並輕鬆將其添加到CardList中。
使用過程代碼,在佈局中聲明MaterialListView:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin">
- <com.dexafree.materiallistviewexample.view.MaterialListView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/material_listview"/>
- </RelativeLayout>
6. android-floating-action-button
Floating Action Button(FAB)是衆多專家大牛針對Material Design討論比較細化的一個點,通過圓形元素與分割線、卡片、各種Bar的直線形成鮮明對比,並使用色彩設定中鮮豔的輔色,帶來更具突破性的視覺效果。也正因如此,在Github上,有着許多與FAB相關的開源項目,基於Material Design規範的開源Android浮動Action Button控件android-floating-action-button便是其中之一。
其主要特性如下:
- 支持常規56dp和最小40dp的按鈕;
- 支持自定義正常、Press狀態以及可拖拽圖標的按鈕背景顏色;
- AddFloatingActionButton類能夠讓開發者非常方便地直接在代碼中寫入加號圖標;
- FloatingActionsMenu類支持展開/摺疊顯示動作。
相關鏈接:android-floating-action-button的mobilehub主頁
7. android-ui
android-ui是Android UI組件類庫,支持Android API 14+,包含了ActionView、RevealColorView等UI組件。其中,ActionView可使Action動作顯示動畫效果,而RevealColorView則帶來了Android 5.0中的圓形顯示/隱藏動畫體驗。
Material Menu爲開發者帶來了非常酷炫的Android菜單、返回、刪除以及檢查按鈕變形,完全控制動畫,併爲開發者提供了兩種MaterialMenuDrawable包裝。
自定義顏色等操作:
- // change color
- MaterialMenu.setColor(int color)
- // change transformation animation duration
- MaterialMenu.setTransformationDuration(int duration)
- // change pressed animation duration
- MaterialMenu.setPressedDuration(int duration)
- // change transformation interpolator
- MaterialMenu.setInterpolator(Interpolator interpolator)
- // set RTL layout support
- MaterialMenu.setRTLEnabled(boolean enabled)
相關鏈接:Material Menu的mobilehub主頁
9. Android-ObservableScrollView
Android-ObservableScrollView是一款用於在滾動視圖中觀測滾動事件的Android庫。它能夠輕而易舉地與Android 5.0 Lollipop引進的工具欄(Toolbar)進行交互,還可以幫助開發者實現擁有Material Design應用視覺體驗的界面外觀,支持ListView、ScrollView、WebView、RecyclerView、GridView組件。
交互代碼回調:
- @Override
- public void onUpOrCancelMotionEvent(ScrollState scrollState) {
- ActionBar ab = getSupportActionBar();
- if (scrollState == ScrollState.UP) {
- if (ab.isShowing()) {
- ab.hide();
- }
- } else if (scrollState == ScrollState.DOWN) {
- if (!ab.isShowing()) {
- ab.show();
- }
- }
- }
相關鏈接:Android-ObservableScrollView的mobilehub主頁
最後,再來介紹一下Google Material Design規範的官方開源圖標集Material Design Icons。良心Google開源了包括Material Design系統圖標包在內的750個字形,涵蓋動作、音視頻、通信、內容、編輯器、文件、硬件、圖像、地圖、導航、通知、社交等各個方面,適用於Web、Android和iOS應用開發,絕對是開發者及設計師必備的資源。
圖標格式主要包括:
- SVG格式,24px和48px;
- SVG和CSS Sprites;
- 適用於Web平臺的1x、2x PNG格式圖標;
- 適用於iOS的1x、2x、3x PNG圖標;
- 所有圖標的Hi-dpi版本(hdpi、mdpi、xhdpi、xxhdpi、xxxhdpi)