介于擬物和扁平之間的Material Design自面世以來粟誓,便引起了很多人的關(guān)注與思考寺谤,就此產(chǎn)生的討論也不絕于耳。本文詳細(xì)介紹了在Android開發(fā)者圈子里頗受青睞的十個Material Design開源項目吮播,從示例变屁、FAB舆乔、菜單来累、動畫沸停、Ripple到Dialog当窗,看被稱為“Google第一次在設(shè)計語言和規(guī)范上超越了Apple”的Material Design是如何逐漸成為App的一種全新設(shè)計標(biāo)準(zhǔn)歪脏。
1. MaterialDesignLibrary
在眾多新晉庫中宵膨,MaterialDesignLibrary可以說是頗受開發(fā)者矚目的一個控件效果庫运杭,能夠讓開發(fā)者在Android 2.2系統(tǒng)上使用Android 5.0才支持的控件效果蛹头,比如扁平院塞、矩形遮晚、浮動按鈕,復(fù)選框以及各式各樣的進度指示器等拦止。
除上述之外县遣,MaterialDesignLibrary還擁有SnackBar、Dialog汹族、Color selector組件萧求,可非常便捷地對應(yīng)用界面進行設(shè)置。
進度指示器樣式效果設(shè)置:
<com.gc.materialdesign.views.ProgressBarCircularIndetermininate
android:id="@+id/progressBarCircularIndetermininate"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#1E88E5" />
Dialog:
Dialog dialog = new Dialog(Context context,String title, String message);
dialog.show();
相關(guān)鏈接:MaterialDesignLibrary的mobilehub主頁
2. RippleEffect
由來自法蘭西的Robin Chutaux開發(fā)的RippleEffect基于MIT許可協(xié)議開源顶瞒,能夠在Android API 9+上實現(xiàn)Material Design夸政,為開發(fā)者提供了一種極為簡易的方式來創(chuàng)建帶有可擴展視圖的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>
相關(guān)鏈接:RippleEffect的mobilehub主頁
3. MaterialEditText
隨著Material Design的到來守问,AppCompat v21也為開發(fā)者提供了Material Design的控件外觀支持,其中就包括EditText坑资,但卻并不好用酪碘,沒有設(shè)置顏色的API,也沒有任何Google Material Design Spec中提到的特性盐茎。于是兴垦,來自國內(nèi)的開發(fā)者“扔物線”開發(fā)了MaterialEditText庫,直接繼承EditText,無需修改Java文件即能實現(xiàn)自定義控件顏色探越。
自定義Base Color:
app:baseColor="#0056d3"
自定義Error Color:
app:maxCharacters="10"
app:errorColor="#ddaa00"
相關(guān)鏈接:MaterialEditText的mobilehub主頁
4. Android-LollipopShowcase
Android-LollipopShowcase是由來自奧地利的移動狡赐、后端及Web開發(fā)者Mike Penz所開發(fā)的演示應(yīng)用,集中演示了新Material Design中所有的UI效果钦幔,以及Android Lollipop中其他非痴硖耄酷炫的特性元素,比如Toolbar鲤氢、RecyclerView搀擂、ActionBarDrawerToggle、Floating Action Button(FAB)卷玉、Android Compat Theme等哨颂。
相關(guān)鏈接:Android-LollipopShowcase的mobilehub主頁
5. MaterialList
MaterialList是一個能夠幫助所有Android開發(fā)者獲取谷歌UI設(shè)計規(guī)范中新增的CardView(卡片視圖)的開源庫,支持Android 2.3+系統(tǒng)相种。作為ListView的擴展威恼,MaterialList可以接收、存儲卡片列表寝并,并根據(jù)它們的Android風(fēng)格和設(shè)計模式進行展示箫措。此外,開發(fā)者還可以創(chuàng)建專屬于自己的卡片布局衬潦,并輕松將其添加到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>
相關(guān)鏈接:MaterialList的mobilehub主頁
6. android-floating-action-button
Floating Action Button(FAB)是眾多專家大牛針對Material Design討論比較細(xì)化的一個點镀岛,通過圓形元素與分割線附迷、卡片、各種Bar的直線形成鮮明對比哎媚,并使用色彩設(shè)定中鮮艷的輔色喇伯,帶來更具突破性的視覺效果。也正因如此拨与,在Github上稻据,有著許多與FAB相關(guān)的開源項目,基于Material Design規(guī)范的開源Android浮動Action Button控件android-floating-action-button便是其中之一买喧。
其主要特性如下:
支持常規(guī)56dp和最小40dp的按鈕捻悯;
支持自定義正常、Press狀態(tài)以及可拖拽圖標(biāo)的按鈕背景顏色淤毛;
AddFloatingActionButton類能夠讓開發(fā)者非常方便地直接在代碼中寫入加號圖標(biāo)今缚;
FloatingActionsMenu類支持展開/折疊顯示動作。
相關(guān)鏈接:android-floating-action-button的mobilehub主頁
7. android-ui
android-ui是Android UI組件類庫低淡,支持Android API 14+姓言,包含了ActionView瞬项、RevealColorView等UI組件。其中何荚,ActionView可使Action動作顯示動畫效果囱淋,而RevealColorView則帶來了Android 5.0中的圓形顯示/隱藏動畫體驗。
相關(guān)鏈接:android-ui的mobilehub主頁
8. Material Menu
Material Menu為開發(fā)者帶來了非巢吞粒酷炫的Android菜單妥衣、返回、刪除以及檢查按鈕變形戒傻,完全控制動畫税手,并為開發(fā)者提供了兩種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)
相關(guān)鏈接:Material Menu的mobilehub主頁
9. Android-ObservableScrollView
Android-ObservableScrollView是一款用于在滾動視圖中觀測滾動事件的Android庫需纳。它能夠輕而易舉地與Android 5.0 Lollipop引進的工具欄(Toolbar)進行交互芦倒,還可以幫助開發(fā)者實現(xiàn)擁有Material Design應(yīng)用視覺體驗的界面外觀,支持ListView候齿、ScrollView、WebView闺属、RecyclerView慌盯、GridView組件。
交互代碼回調(diào):
@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();
}
}
}
相關(guān)鏈接:Android-ObservableScrollView的mobilehub主頁
10. Material Design Icons
最后掂器,再來介紹一下Google Material Design規(guī)范的官方開源圖標(biāo)集Material Design Icons亚皂。良心Google開源了包括Material Design系統(tǒng)圖標(biāo)包在內(nèi)的750個字形,涵蓋動作国瓮、音視頻灭必、通信、內(nèi)容乃摹、編輯器禁漓、文件、硬件孵睬、圖像播歼、地圖、導(dǎo)航掰读、通知秘狞、社交等各個方面,適用于Web蹈集、Android和iOS應(yīng)用開發(fā)烁试,絕對是開發(fā)者及設(shè)計師必備的資源。
圖標(biāo)格式主要包括:
SVG格式拢肆,24px和48px减响;
SVG和CSS Sprites靖诗;
適用于Web平臺的1x、2x PNG格式圖標(biāo)辩蛋;
適用于iOS的1x呻畸、2x、3x PNG圖標(biāo)悼院;
所有圖標(biāo)的Hi-dpi版本(hdpi伤为、mdpi、xhdpi据途、xxhdpi绞愚、xxxhdpi)。
相關(guān)鏈接:Material Design Icons的mobilehub主頁