Android Material Design 筆記2

material design 筆記2

一.沉浸

1.什么是沉浸鸠天?傳統(tǒng)的手機(jī)狀態(tài)欄是呈現(xiàn)出黑色條狀的讼育,有的和手機(jī)主界面有很明顯的區(qū)別。這一樣就在一定程度上犧牲了視覺寬度稠集,界面面積變小奶段。沉浸式是APP界面圖片延伸到狀態(tài)欄, 應(yīng)用本身沉浸于狀態(tài)欄剥纷,所以如果第三方的軟件沒有為狀態(tài)欄分配圖片痹籍,那么自然就是黑色。頂端的狀態(tài)欄和下面的虛擬按鍵都隱藏晦鞋,需要的時(shí)候從邊緣劃出蹲缠。
當(dāng)啟用該模式棺克,應(yīng)用程序的界面將占據(jù)整個(gè)屏幕,系統(tǒng)自動(dòng)將隱藏系統(tǒng)的狀態(tài)欄和導(dǎo)航欄线定,讓應(yīng)用程序內(nèi)容可以在最大顯示范圍呈現(xiàn)娜谊,增加大屏體驗(yàn),而當(dāng)需要查看通知的時(shí)候只需要從頂部向下滑動(dòng)就能呼出通知欄斤讥。

沉浸模式實(shí)際上有兩種:
一種叫“沉浸模式”纱皆,狀態(tài)欄和虛擬按鈕會(huì)自動(dòng)隱藏、應(yīng)用自動(dòng)全屏芭商,這種模式下派草,應(yīng)用占據(jù)屏幕的全部空間, 只有當(dāng)用戶從屏幕的上方邊沿處向下劃動(dòng)時(shí)铛楣, 才會(huì)退出沉浸模式近迁, 用戶觸摸屏幕其它部分時(shí), 不會(huì)退出該模式蛉艾, 這種模式比較適用于閱讀器钳踊、 雜志類應(yīng)用。

另外一種叫“黏性沉浸模式”勿侯,讓狀態(tài)欄和虛擬按鈕半透明,應(yīng)用使用屏幕的全部空間缴罗, 當(dāng)用戶從屏幕的上方邊沿處向下滑動(dòng)時(shí)助琐,也不會(huì)退出該模式, 但是系統(tǒng)界面 (狀態(tài)欄面氓、 導(dǎo)航欄) 將會(huì)以半透明的效果浮現(xiàn)在應(yīng)用視圖之上 兵钮, 只有當(dāng)用戶點(diǎn)擊系統(tǒng)界面上的控件時(shí), 才會(huì)退出黏性沉浸模式舌界。

2.Android 實(shí)現(xiàn)沉浸

android從4.4開始掘譬,開始支持UI使用StatusBar與NavigationBar的范圍。
所以要進(jìn)行下面的配置:
在value中的styles.xml中設(shè)置

<!-- Base application theme. -->
<style name="AppTheme.Base"     parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>

在value-v19中的styles.xml中設(shè)置(為了兼容4.4)

<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>

在value-v21中的styles.xml中設(shè)置

<style name="AppTheme" parent="AppTheme.Base">
<!--透明狀態(tài)欄-->
<item name="android:windowTranslucentStatus">true</item>
<!--透明導(dǎo)航欄-->
<item name="android:windowTranslucentNavigation">true</item>
<!--使?fàn)顟B(tài)欄呻拌,導(dǎo)航欄可繪制-->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

二.布局控件

1.CardView葱轩、RecyclerView
Android L(5.0)中新增了兩個(gè)控件分別是CardView,RecyclerView藐握,RecyclerView這個(gè)控件是一個(gè)可以裝載大量的視圖集合靴拱,并且可以非常效率的進(jìn)行回收和滾動(dòng)。當(dāng)你list中的元素經(jīng)常動(dòng)態(tài)改變時(shí)可以使用RecyclerView控件猾普。
RecyclerView非常容易使用袜炕,它提供了如下兩個(gè)功能:
為每個(gè)條目位置提供了layout管理器(RecyclerView.setLayoutManager)
為每個(gè)條目設(shè)置了操作動(dòng)畫(RecyclerView.setItemAnimator)

CardView
CardView繼承自FrameLayout,允許你在card視圖中顯示信息. CardView也可以設(shè)置陰影和圓角初家。
CardView在API 21以下的圓角效果處理
2.com.android.support:design

a.TextInputLayout 提示輸入內(nèi)容
登錄時(shí)可以提示偎窘。

比如:

 <android.support.design.widget.TextInputLayout
            android:id="@+id/input_user_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:counterTextAppearance="@style/counterTextAppearance"
            app:errorTextAppearance="@style/errorTextAppearance"
            app:hintTextAppearance="@style/hintTextAppearance">

            <AutoCompleteTextView
                android:id="@+id/tv_user_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/login_user_name_hint"
                android:imeOptions="actionNext"
                android:maxLength="20"
                android:maxLines="1"
                android:singleLine="true"
                android:textSize="@dimen/NormalTextSize" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:counterTextAppearance="@style/counterTextAppearance"
            app:errorTextAppearance="@style/errorTextAppearance"
            app:hintTextAppearance="@style/hintTextAppearance"
            app:passwordToggleEnabled="true">

            <EditText
                android:id="@+id/tv_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/login_user_name_password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:maxLength="20"
                android:maxLines="1"
                android:singleLine="true"
                android:textSize="@dimen/NormalTextSize" />
        </android.support.design.widget.TextInputLayout>

注意:

app:counterTextAppearance="@style/counterTextAppearance"
app:errorTextAppearance="@style/errorTextAppearance"
app:hintTextAppearance="@style/hintTextAppearance">

可以自己在style中定義 暗示文字乌助、提示文字、錯(cuò)誤文字陌知、以及的顏色 大小等風(fēng)格眷茁。

    <!-- 登錄相關(guān)-->
<style name="errorTextAppearance" parent="@style/TextAppearance.Design.Error">
    <item name="android:textSize">18sp</item>
</style>

<style name="counterTextAppearance" parent="@style/TextAppearance.Design.Counter">
    <item name="android:textColor">@color/colorPrimaryDark</item>
    <item name="android:textSize">20sp</item>
</style>

<style name="hintTextAppearance" parent="@style/TextAppearance.Design.Hint">
    <item name="android:textColor">@color/colorPrimaryDark</item>
    <item name="android:textSize">20sp</item>
</style>

b.TabLayout
一般與ViewPager配合 fragment一起使用

 <android.support.design.widget.TabLayout
    android:id="@+id/tabLayout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tabLayout_hight"
    android:background="@color/colorPrimary"
    app:tabGravity="fill"
    app:tabIndicatorColor="@color/black_overlay"
    app:tabIndicatorHeight="@dimen/tabIndicatorHeight"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/black"
    app:tabTextAppearance="@style/TabLayoutTextStyle"
    app:tabTextColor="@color/tablayout_select" />


<ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

其中 app:tabMode 兩種模式 scrollable 可滾動(dòng)的; 卷動(dòng); 可卷動(dòng)的;fixed 固定的,不變的;
app:tabGravity 兩種 center 聚集在中間纵诞, fill充滿整個(gè)bar平均分上祈。

TabLayout在布局底部是自帶一條滾動(dòng)條的,為了實(shí)現(xiàn)塊狀切換的效果浙芙,可以把 app:tabIndicatorHeight 屬性設(shè)置為0dp登刺,去掉滾動(dòng)條

 app:tabIndicatorHeight="0dp"

每個(gè)tab添加分割線

  mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
    LinearLayout linearLayout = (LinearLayout) mTabLayout.getChildAt(0);
    linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
            R.drawable.layout_divider_vertical));

在drawable 下邊定義layout_divider_vertical

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black"/>
<size android:width="1dp"/>
</shape>

更改TabLayout選中的背景色

在drawable文件夾下建立選中效果的文件 tab_background_selected.xml和沒選中的效果文件tab_background_unselected.xml color不同而已。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorPrimaryDark"/>
</shape>

在drawable文件夾下建立文件 tab_background_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/tab_background_selected" android:state_selected="true" />
<item android:drawable="@drawable/tab_background_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
</selector>

最后在Style 中新建 Base.Widget.Design.TabLayout 復(fù)寫

   <style name="Base.Widget.Design.TabLayout" parent="android:Widget">
    <item name="tabBackground">@drawable/tab_selector</item>
    
</style>

繼續(xù)整理 2017年10月17日 19:22:56

AppBarLayout
用AppBarLayout可以讓包含在其中的子控件能響應(yīng)被標(biāo)記了ScrollingViewBehavior的的滾動(dòng)事件(要與CoordinatorLayout 一起使用)嗡呼,利用它我們可以很容易的去實(shí)現(xiàn)視差滾動(dòng)效果纸俭。
CoordinatorLayout
協(xié)調(diào)(Coordinate)其他組件, 實(shí)現(xiàn)聯(lián)動(dòng).
掌握 Coordinator Layout

AppbarLayout 嚴(yán)重依賴于CoordinatorLayout,必須用于CoordinatorLayout 的直接子View南窗。

layout_scrollFlags有5種動(dòng)作揍很,分別是 scroll,enterAlways,enterAlwaysCollapsed,exitUntilCollapsed,snap。

  1. scroll ,子View 添加layout_scrollFlags屬性 的值scroll 時(shí)万伤,這個(gè)View將會(huì)隨著可滾動(dòng)View(如:ScrollView,以下都會(huì)用ScrollView 來代替可滾動(dòng)的View )一起滾動(dòng)窒悔,就好像子View 是屬于ScrollView的一部分一樣。

2.enterAlways ,子View 添加layout_scrollFlags屬性 的值有enterAlways 時(shí), 當(dāng)ScrollView 向下滑動(dòng)時(shí)敌买,子View 將直接向下滑動(dòng)简珠,而不管ScrollView 是否在滑動(dòng)。注意:要與scroll 搭配使用虹钮,否者是不能滑動(dòng)的聋庵。

  1. enterAlwaysCollapsed , enterAlwaysCollapsed 是對(duì)enterAlways 的補(bǔ)充,當(dāng)ScrollView 向下滑動(dòng)的時(shí)候芙粱,滑動(dòng)View(也就是設(shè)置了enterAlwaysCollapsed 的View)下滑至折疊的高度祭玉,當(dāng)ScrollView 到達(dá)滑動(dòng)范圍的結(jié)束值的時(shí)候,滑動(dòng)View剩下的部分開始滑動(dòng)春畔。這個(gè)折疊的高度是通過View的minimum height (最小高度)指定的脱货。要配合scroll|enterAlways 一起使用.

4.exitUntilCollapsed, 當(dāng)ScrollView 滑出屏幕時(shí)(也就時(shí)向上滑動(dòng)時(shí)),滑動(dòng)View先響應(yīng)滑動(dòng)事件拐迁,滑動(dòng)至折疊高度蹭劈,也就是通過minimum height 設(shè)置的最小高度后,就固定不動(dòng)了线召,再把滑動(dòng)事件交給 scrollview 繼續(xù)滑動(dòng)铺韧。

5.snap,意思是:在滾動(dòng)結(jié)束后,如果view只是部分可見缓淹,它將滑動(dòng)到最近的邊界哈打。比如塔逃,如果view的底部只有25%可見料仗,它將滾動(dòng)離開屏幕湾盗,而如果底部有75%可見,它將滾動(dòng)到完全顯示氛改。

CollapsingToolbarLayout帐萎、
讓Toolbar可伸縮,在伸縮的時(shí)候決定ToolBar是移除屏幕和固定在最上面胜卤。

屬性意義

1)contentScrim:當(dāng)Toolbar收縮到一定程度時(shí)的所展現(xiàn)的主體顏色疆导。即Toolbar的顏色。
2)title:當(dāng)titleEnable設(shè)置為true的時(shí)候葛躏,在toolbar展開的時(shí)候澈段,顯示大標(biāo)題,toolbar收縮時(shí)舰攒,顯示為toolbar上面的小標(biāo)題败富。
3)scrimAnimationDuration:該屬性控制toolbar收縮時(shí),顏色變化的動(dòng)畫持續(xù)時(shí)間芒率。即顏色變?yōu)閏ontentScrim所指定的顏色進(jìn)行的動(dòng)畫所需要的時(shí)間囤耳。
4)expandedTitleGravity:指定toolbar展開時(shí),title所在的位置偶芍。類似的還有expandedTitleMargin、collapsedTitleGravity這些屬性德玫。
5)collapsedTitleTextAppearance:指定toolbar收縮時(shí)匪蟀,標(biāo)題字體的樣式,

層級(jí):

<android.support.design.widget.CoordinatorLayout...>
<android.support.design.widget.AppBarLayout...>
    <android.support.design.widget.CollapsingToolbarLayout...>
        <!-- your collapsed view -->
        <View.../>
        <android.support.v7.widget.Toolbar.../>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<!-- Scroll view -->
<android.support.v7.widget.RecyclerView.../>
</android.support.design.widget.CoordinatorLayout>

FloatingActionButton
浮動(dòng)按鈕

app:borderWidth=""------------------邊框?qū)挾仍咨ǔTO(shè)置為0 材彪,用于解決Android 5.X設(shè)備上陰影無法正常顯示的問題
app:backgroundTint=""---------------按鈕的背景顏色,不設(shè)置琴儿,默認(rèn)使用theme中colorAccent的顏色
app:rippleColor=""--------------------點(diǎn)擊的邊緣陰影顏色
app:elevation=""----------------------邊緣陰影的寬度
app:pressedTranslationZ="16dp"-----點(diǎn)擊按鈕時(shí)段化,按鈕邊緣陰影的寬度,通常設(shè)置比elevation的數(shù)值大

NavigationView造成、
抽屜式的導(dǎo)航控件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.mobiletrain.drawerlayout.MainActivity">

<LinearLayout
    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:text="主頁面"/>
</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/header_layout"
    app:menu="@menu/main"></android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

1.android:layout_gravity="left"屬性表示該View是左邊的滑出菜單显熏,這個(gè)屬性的含義不用多說,這是DrawerLayout使用方式中的知識(shí)點(diǎn)晒屎。
2.app:headerLayout="@layout/header_layout"表示引用一個(gè)頭布局文件喘蟆,這個(gè)頭就是我們?cè)谏厦婵吹降哪莻€(gè)背景圖片缓升,包括背景圖片上面的顯示用戶名的控件等等。
3.app:menu="@menu/main"表示引用一個(gè)menu作為下面的點(diǎn)擊項(xiàng)

Snackbar
SnackBar通過在屏幕底部展示簡潔的信息蕴轨,為一個(gè)操作提供了一個(gè)輕量級(jí)的反饋港谊,并且在Snackbar中還可以包含一個(gè)操作,在同一時(shí)間內(nèi)橙弱,僅且只能顯示一個(gè) Snackbar歧寺,它的顯示依賴于UI,不像Toast那樣可以脫離應(yīng)用顯示棘脐。它的用法和Toast很相似斜筐,唯一不同的就是它的第一個(gè)參數(shù)不是傳入Context而是傳入它所依附的父視圖,但是他比Toast更強(qiáng)大荆残。
未實(shí)際應(yīng)用奴艾,參考
參考http://www.reibang.com/p/cd1e80e64311/

2017年10月17日 19:38:37

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市内斯,隨后出現(xiàn)的幾起案子蕴潦,更是在濱河造成了極大的恐慌,老刑警劉巖俘闯,帶你破解...
    沈念sama閱讀 218,122評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件潭苞,死亡現(xiàn)場離奇詭異,居然都是意外死亡真朗,警方通過查閱死者的電腦和手機(jī)此疹,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來遮婶,“玉大人蝗碎,你說我怎么就攤上這事∑炱耍” “怎么了蹦骑?”我有些...
    開封第一講書人閱讀 164,491評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長臀防。 經(jīng)常有香客問我眠菇,道長,這世上最難降的妖魔是什么袱衷? 我笑而不...
    開封第一講書人閱讀 58,636評(píng)論 1 293
  • 正文 為了忘掉前任捎废,我火速辦了婚禮,結(jié)果婚禮上致燥,老公的妹妹穿的比我還像新娘登疗。我一直安慰自己,他們只是感情好篡悟,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,676評(píng)論 6 392
  • 文/花漫 我一把揭開白布谜叹。 她就那樣靜靜地躺著匾寝,像睡著了一般。 火紅的嫁衣襯著肌膚如雪荷腊。 梳的紋絲不亂的頭發(fā)上艳悔,一...
    開封第一講書人閱讀 51,541評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音女仰,去河邊找鬼猜年。 笑死,一個(gè)胖子當(dāng)著我的面吹牛疾忍,可吹牛的內(nèi)容都是我干的乔外。 我是一名探鬼主播,決...
    沈念sama閱讀 40,292評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼一罩,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼杨幼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起聂渊,我...
    開封第一講書人閱讀 39,211評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤差购,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后汉嗽,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體欲逃,經(jīng)...
    沈念sama閱讀 45,655評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,846評(píng)論 3 336
  • 正文 我和宋清朗相戀三年饼暑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了稳析。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,965評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡弓叛,死狀恐怖彰居,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情撰筷,我是刑警寧澤裕菠,帶...
    沈念sama閱讀 35,684評(píng)論 5 347
  • 正文 年R本政府宣布,位于F島的核電站闭专,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏旧烧。R本人自食惡果不足惜影钉,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,295評(píng)論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望掘剪。 院中可真熱鬧平委,春花似錦、人聲如沸夺谁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,894評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至蜡塌,卻和暖如春碉纳,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背馏艾。 一陣腳步聲響...
    開封第一講書人閱讀 33,012評(píng)論 1 269
  • 我被黑心中介騙來泰國打工劳曹, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人琅摩。 一個(gè)月前我還...
    沈念sama閱讀 48,126評(píng)論 3 370
  • 正文 我出身青樓铁孵,卻偏偏與公主長得像,于是被迫代替她去往敵國和親房资。 傳聞我的和親對(duì)象是個(gè)殘疾皇子蜕劝,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,914評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,133評(píng)論 25 707
  • 內(nèi)容抽屜菜單ListViewWebViewSwitchButton按鈕點(diǎn)贊按鈕進(jìn)度條TabLayout圖標(biāo)下拉刷新...
    皇小弟閱讀 46,759評(píng)論 22 665
  • 空洞洞的我 像個(gè)木頭一樣
    喜歡兔牙閱讀 119評(píng)論 0 0
  • 單條數(shù)據(jù)查詢 url:rest/currency/{id}/get method:get request:id傳入...
    cltclt閱讀 413評(píng)論 0 0