Android Design Support Library初探-更新中
導(dǎo)讀
這個(gè)兼容庫(kù)容易和Google之前發(fā)布的 Android Support Library 22.1 混淆,兩者的區(qū)別在于:
- Android Support Library 22.1 只是支持了一些基本空間的材料設(shè)計(jì)化,
- Android Design Support Library 更多的是對(duì)一些特效的實(shí)現(xiàn),這個(gè)庫(kù)和github上的很多開源的項(xiàng)目有很大的關(guān)系,material design的很多效果,同一種效果在github上有太多的實(shí)現(xiàn),現(xiàn)在官方將其標(biāo)準(zhǔn)化了。
- -
原文地址
如果你的英文666666,那就來(lái)這里看吧~
Android Design Support Library
重要控件
Android 5.0是有史以來(lái)最重要的Android版本之一,這其中大部分歸功于material design的引入,這種新的設(shè)計(jì)語(yǔ)言讓整個(gè)Android的用戶體驗(yàn)煥然一新。 官方的詳細(xì)專題有更詳細(xì)的說(shuō)明來(lái)介紹使用material design帶來(lái)的好處。但我們也知道,這種設(shè)計(jì)對(duì)于開發(fā)者來(lái)講,尤其是在意向后兼容的開發(fā)者來(lái)說(shuō)是一種挑戰(zhàn)。
在Android Design Support Library的幫助下,我們?yōu)樗械拈_發(fā)者,所有的2.1以上的設(shè)備,帶來(lái)了一些重要的material design控件。
比如:
navigation drawer view, floating labels for editing text, a floating action button, snackbar, tabs, and a motion and scroll framework to tie them together.
- navigation drawer view,
- floating labels for editing text(輸入控件的懸浮標(biāo)簽)
- floating action button (懸浮操作按鈕)
- snackbar
- tabs(選項(xiàng)卡)
- a motion and scroll framework to tie them together(將這些控件結(jié)合在一起的手勢(shì)滾動(dòng)框架)
官方視頻簡(jiǎn)介
Navigation View
抽屜導(dǎo)航是app識(shí)別度與內(nèi)部導(dǎo)航的關(guān)鍵,保持這里設(shè)計(jì)上的一致對(duì)app的可用性至關(guān)重要,尤其是對(duì)第一次使用的用戶。NavigationView 通過(guò)提供抽屜導(dǎo)航所需要的框架讓實(shí)現(xiàn)更簡(jiǎn)單,同時(shí)它還能夠直接通過(guò)菜單資源文件來(lái)直接生成導(dǎo)航元素。
把NavigationView 作為DrawerLayout的內(nèi)容視圖來(lái)使用,比如下面的布局:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"><!-- your content layout --><android.support.design.widget.NavigationView android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_gravity="start"app:headerLayout="@layout/drawer_header"app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout>你會(huì)注意到NavigationView的兩個(gè)屬性:
- app:headerLayout :控制頭部的布局(可選)
- app:menu:導(dǎo)航菜單的資源文件(必選),也可以在運(yùn)行時(shí)配置。
NavigationView處理好了和狀態(tài)欄的關(guān)系,可以確保NavigationView在API21(5.0)設(shè)備上正確的和狀態(tài)欄交互。
最簡(jiǎn)單的抽屜菜單就是幾個(gè)可點(diǎn)擊的菜單集合:
<group android:checkableBehavior="single"><item android:id="@+id/navigation_item_1"android:checked="true"android:icon="@drawable/ic_android"android:title="@string/navigation_item_1"/><item android:id="@+id/navigation_item_2"android:icon="@drawable/ic_android"android:title="@string/navigation_item_2"/> </group>被點(diǎn)擊過(guò)的item會(huì)高亮顯示在抽屜菜單中,讓用戶知道哪個(gè)菜單被選中。
你也可以在menu中使用subheader來(lái)為菜單分組:
<itemandroid:id="@+id/navigation_subheader"android:title="@string/navigation_subheader"><menu><itemandroid:id="@+id/navigation_sub_item_1"android:icon="@drawable/ic_android"android:title="@string/navigation_sub_item_1"/><itemandroid:id="@+id/navigation_sub_item_2"android:icon="@drawable/ic_android"android:title="@string/navigation_sub_item_2"/></menu> </item>你可以設(shè)置一個(gè)OnNavigationItemSelectedListener,使用起setNavigationItemSelectedListener()來(lái)獲取元素被選中的回調(diào)時(shí)間,它為你提供被點(diǎn)擊的 菜單元素 ,讓你可以處理選擇事件,改變復(fù)選框狀態(tài),加載新內(nèi)容,關(guān)閉導(dǎo)航菜單,以及其他任何你想做的操作。
效果和Code請(qǐng)移步 NavigationDrawer和NavigationView-Android M新控件
輸入框控件的懸浮標(biāo)簽
在material design中,即使是簡(jiǎn)單的EditText,也有提升的余地。 通常EditText會(huì)在用戶輸入第一個(gè)字母后隱藏提示信息,但是現(xiàn)在可以使用TextInputLayout來(lái)將EditText封裝起來(lái),提示信息(hint)會(huì)變成一個(gè)顯示在EditText之上的floating label,這樣用戶就始終知道他們現(xiàn)在輸入的是什么了。
TextInputLayout:
Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text. Also supports showing an error via setErrorEnabled(boolean) and setError(CharSequence).
效果圖
Code
第一步 加入依賴
本工程的build.gradle中
compile 'com.android.support:design:23.1.1'懸浮操作按鈕 Floating Action Button
Snackbar
選項(xiàng)卡
CoordinatorLayout, 手勢(shì), 以及滾動(dòng)
CoordinatorLayout與懸浮操作按鈕
CoordinatorLayout與app bar
可伸縮折疊的Toolbar (Collapsing Toolbar)
CoordinatorLayout與自定義view
參考文檔
官方博客
官方文檔
官方Demo
總結(jié)
以上是生活随笔為你收集整理的Android Design Support Library初探-更新中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: NavigationDrawer和Nav
- 下一篇: TextInputLayout-Andr