來自:http://www.csdn.net/article/2014-11-21/2822753-material-design-libs/1
介於擬物和扁平之間的Material Design自面世以來,便引起了很多人的關注與思考,就此產生的討論也不絕於耳。本文詳細介紹了在Android開發者圈子里頗受青睞的十個Material Design開源項目,從示例、FAB、菜單、動畫、Ripple到Dialog,看被稱為“Google第一次在設計語言和規范上超越了Apple”的Material Design是如何逐漸成為App的一種全新設計標准。
在眾多新晉庫中,MaterialDesignLibrary可以說是頗受開發者矚目的一個控件效果庫,能夠讓開發者在Android 2.2系統上使用Android 5.0才支持的控件效果,比如扁平、矩形、浮動按鈕,復選框以及各式各樣的進度指示器等。
除上述之外,MaterialDesignLibrary還擁有SnackBar、Dialog、Color selector組件,可非常便捷地對應用界面進行設置。
進度指示器樣式效果設置:
Dialog:
Dialog dialog = new Dialog(Context context,String title, String message); dialog.show();
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"
Android-LollipopShowcase是由來自奧地利的移動、后端及Web開發者Mike Penz所開發的演示應用,集中演示了新Material Design中所有的UI效果,以及Android Lollipop中其他非常酷炫的特性元素,比如Toolbar、RecyclerView、ActionBarDrawerToggle、Floating Action Button(FAB)、Android Compat Theme等。
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類支持展開/折疊顯示動作。
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)
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(); } } }
最后,再來介紹一下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)。