材料新特性

這篇文章主要是方便以后我去查找材料特性的使用方式澜驮,并不會作過多的分析忿晕。如果想了解更多材料特性的使用方式請參考https://developer.android.com/design/

這是我實(shí)現(xiàn)的效果圖获雕,需要完整demo的朋友可以私我

ToolBar作用

用來替換ActionBar,單獨(dú)使用的情況較少;我個人更喜歡搭配android:fitsSsystemWindows (背景圖和系統(tǒng)狀態(tài)欄融合)使用。
舉例:

        <!--android:theme:設(shè)置toolbar上各種元素的顏色-->
        <!--app:popupTheme:彈出的菜單項(xiàng)指定顏色-->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <!--toolbar整體顏色-->
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--導(dǎo)航欄顏色-->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <!--FloatingButton和按鈕的顏色-->
        <item name="colorAccent">@color/colorAccent</item>
        <!--App文本顏色-->
        <item name="android:textColorPrimary">@android:color/black</item>
        <!--主體背景顏色-->
        <item name="android:windowBackground">@android:color/white</item>
        <!--底部導(dǎo)航欄顏色-->
        <item name="android:navigationBarColor">@android:color/holo_red_light</item>
    </style>
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
 //設(shè)置側(cè)滑菜單圖標(biāo)
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeAsUpIndicator(R.drawable.menu);
        }

DrawerLayout+NavigationView使用

DrawerLayout作為Material側(cè)滑菜單蒲犬,必須作為頂層布局;NavigationView包含兩個布局的引用岸啡,一個是導(dǎo)航里面的頭部原叮,另一個是菜單項(xiàng);
舉例:

<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:id="@+id/drawerlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.p00746.googlemapdemo.materialDemo.MaterialActivity">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <include layout="@layout/page_start" />
    
    <!--側(cè)滑菜單項(xiàng)-->
    <!--android:layout_gravity="start"必須指定-->
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="none">
        <item
            android:id="@+id/nav_recycler_and_swipe_refresh"
            android:icon="@drawable/ic_format_list_bulleted_black_24dp"
            android:title="@string/nav_recycler_view" />
        <item
            android:id="@+id/nav_scrolling"
            android:icon="@drawable/ic_file_download_black_24dp"
            android:title="@string/nav_scrolling" />
        <item
            android:id="@+id/nav_full_screen"
            android:icon="@drawable/ic_fullscreen_black_24dp"
            android:title="@string/nav_fullscreen" />
        <item
            android:id="@+id/nav_bottom_navigation"
            android:icon="@drawable/ic_more_horiz_black_24dp"
            android:title="@string/nav_bottom_navigation" />
        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/nav_settings" />
    </group>

    <group android:id="@+id/group_about">
        <item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_info_black_24dp"
            android:title="@string/nav_about" />
        <item
            android:id="@+id/nav_donate"
            android:icon="@drawable/ic_monetization_on_black_24dp"
            android:title="@string/nav_donate" />
        <item
            android:id="@+id/nav_my_apps"
            android:icon="@drawable/ic_apps_black_24dp"
            android:title="@string/nav_my_apps" />
    </group>

</menu>
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerlayout);
        //DrawerLayout相關(guān)設(shè)置
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
                drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //更改菜單icon和title顏色變化效果
        navigationView.setItemIconTintList(null);
        View headerView = navigationView.getHeaderView(0);
        nav_header = (LinearLayout) headerView.findViewById(R.id.nav_header);
        nav_header.setOnClickListener(this);

CoordinatorLayout+AppBarLayout的使用

CoordinatorLayout加強(qiáng)版的FrameLayout巡蘸,用來協(xié)調(diào)Material各種控件奋隶。AppBarLayout加強(qiáng)版的LinearLayout,內(nèi)部阻力很多滾動事件封裝≡没模可以設(shè)置layout_scrollFlags屬性讓控件具有一些炫酷效果唯欣;

  • scroll:View會隨著滾動事件一起移動
  • enterAlways:View向下滾動時(shí),該View會直接往下滾動
  • exitUntilCollapsed:View向上逐漸消失時(shí)逾冬,會一直往上滑動黍聂,直到剩下的高度達(dá)到它最小高度后躺苦,在響應(yīng)內(nèi)部事件
  • enterAlwaysCollapsed:一般跟enterAlways一起使用,它是指产还,View在往下“出現(xiàn)”的時(shí)候匹厘,首先是enterAlways效果,當(dāng)View的高度達(dá)到最小高度時(shí)脐区,View就暫時(shí)不去往下滾動愈诚,直到ScrollView滑動到頂部不再滑動時(shí),View再繼續(xù)往下滑動牛隅,直到滑到View的頂部結(jié)束
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">
        <!--android:theme:設(shè)置toolbar上各種元素的顏色-->
        <!--app:popupTheme:彈出的菜單項(xiàng)指定顏色-->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@color/colorAccent" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add_white_24dp"
        android:visibility="gone"
        app:layout_scrollFlags="scroll|enterAlways" />

</android.support.design.widget.CoordinatorLayout>

CollapsingToolbarLayout的作用

加強(qiáng)版的ToolBar炕柔,只能作為AppBarlayout的直接布局來使用,AppBarLayout又必須是CoordinatorLayout的子布局;

<android.support.design.widget.CoordinatorLayout 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:id="@+id/activity_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.p00746.googlemapdemo.materialDemo.ScrollViewActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_scrolling"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height_image_view"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <!--app:contentScrim="?attr/colorPrimary" 趨于折疊時(shí)的顏色-->
        <!--layout_collapseMode-->
        <!--pin:折疊的過程中位置始終保持不變-->
        <!--parallax:折疊過程中產(chǎn)生一定的錯位偏移-->
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/image_scrolling_top"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_scrolling"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/big_activity_fab_margin"
        android:src="@drawable/ic_share_white_24dp"
        app:layout_anchor="@id/app_bar_scrolling"
        app:layout_anchorGravity="bottom|end" />

    <include layout="@layout/content_scrolling" />

</android.support.design.widget.CoordinatorLayout>

TextInputLayout的使用

TextInputLayout 控件表現(xiàn)得就像LinearLayout 一樣媒佣,它是一個容器匕累。TextInputLayout 中只能放一個子元素,和ScrollView有點(diǎn)類似默伍,并且子元素必須是EditText欢嘿;
TextInputLayout 實(shí)現(xiàn)的功能就是當(dāng)EditText中輸入第一個字母要隱藏hint的時(shí)候,TextInputLayout中會出現(xiàn)一個懸浮的標(biāo)簽來顯示這個hint也糊,還負(fù)責(zé)一個炫酷的的material 動畫

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

                <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.support.design.widget.TextInputLayout>

底部導(dǎo)航欄的另一種實(shí)現(xiàn)方式(3-5之間使用)

<LinearLayout 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:id="@+id/activity_bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".materialDemo.BottomNavigationActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager_bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/white"
        app:itemIconTint="@color/nav_color_select"
        app:itemTextColor="@color/nav_color_select"
        app:menu="@menu/bottom_navigation" />

</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/bottom_navigation_blue"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="Blue" />

    <item
        android:id="@+id/bottom_navigation_green"
        android:icon="@drawable/ic_photo_black_24dp"
        android:title="Green" />

    <item
        android:id="@+id/bottom_navigation_yellow"
        android:icon="@drawable/ic_music_note_black_24dp"
        android:title="Yellow" />

    <item
        android:id="@+id/bottom_navigation_red"
        android:icon="@drawable/ic_movie_black_24dp"
        android:title="Red" />
</menu>
// If BottomNavigationView has more than 3 items, using reflection to disable shift mode       
BottomNavigationViewHelper.disableShiftMode(navigation);

CardView 的使用

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_main_1_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/main_card_margin_vertical"
    android:layout_marginEnd="@dimen/main_card_margin_horizontal"
    android:layout_marginStart="@dimen/main_card_margin_horizontal"
    android:layout_marginTop="@dimen/main_card_margin_vertical"
    android:background="?attr/selectableItemBackgroundBorderless"
    card_view:cardCornerRadius="@dimen/card_recycler_corner_radius"
    card_view:cardElevation="@dimen/card_recycler_elevation">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/img_main_card_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:src="@drawable/material_design_2"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/tv_card_main_1_title"
            style="@style/TextAppearance.AppCompat.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/img_main_card_1"
            android:layout_marginEnd="@dimen/card_title_margin"
            android:layout_marginStart="@dimen/card_title_margin"
            android:layout_marginTop="@dimen/card_title_margin_top"
            android:text="@string/main_card_title"
            android:textColor="@color/black" />

        <TextView
            android:id="@+id/tv_card_main1_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_card_main_1_title"
            android:layout_marginBottom="@dimen/card_subtitle_margin"
            android:layout_marginEnd="@dimen/card_subtitle_margin"
            android:layout_marginStart="@dimen/card_subtitle_margin"
            android:layout_marginTop="@dimen/card_button_margin"
            android:text="@string/main_card_subtitle" />

        <Button
            android:id="@+id/btn_card_main1_action1"
            style="@style/Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_card_main1_subtitle"
            android:layout_margin="@dimen/card_button_margin"
            android:text="@string/main_card_button_1"
            android:textColor="@color/colorAccent" />

        <Button
            android:id="@+id/btn_card_main1_action2"
            style="@style/Widget.AppCompat.Button.Borderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_card_main1_subtitle"
            android:layout_marginBottom="@dimen/card_button_margin"
            android:layout_marginTop="@dimen/card_button_margin"
            android:layout_toEndOf="@id/btn_card_main1_action1"
            android:text="@string/main_card_button_2"
            android:textColor="@color/colorAccent" />

    </RelativeLayout>
</android.support.v7.widget.CardView>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末炼蹦,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子狸剃,更是在濱河造成了極大的恐慌掐隐,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,126評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件钞馁,死亡現(xiàn)場離奇詭異虑省,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)指攒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評論 2 382
  • 文/潘曉璐 我一進(jìn)店門慷妙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人允悦,你說我怎么就攤上這事÷瞧。” “怎么了隙弛?”我有些...
    開封第一講書人閱讀 152,445評論 0 341
  • 文/不壞的土叔 我叫張陵,是天一觀的道長狞山。 經(jīng)常有香客問我全闷,道長,這世上最難降的妖魔是什么萍启? 我笑而不...
    開封第一講書人閱讀 55,185評論 1 278
  • 正文 為了忘掉前任总珠,我火速辦了婚禮屏鳍,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘局服。我一直安慰自己钓瞭,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評論 5 371
  • 文/花漫 我一把揭開白布淫奔。 她就那樣靜靜地躺著山涡,像睡著了一般。 火紅的嫁衣襯著肌膚如雪唆迁。 梳的紋絲不亂的頭發(fā)上鸭丛,一...
    開封第一講書人閱讀 48,970評論 1 284
  • 那天,我揣著相機(jī)與錄音唐责,去河邊找鬼鳞溉。 笑死,一個胖子當(dāng)著我的面吹牛鼠哥,可吹牛的內(nèi)容都是我干的熟菲。 我是一名探鬼主播,決...
    沈念sama閱讀 38,276評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼肴盏,長吁一口氣:“原來是場噩夢啊……” “哼科盛!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起菜皂,我...
    開封第一講書人閱讀 36,927評論 0 259
  • 序言:老撾萬榮一對情侶失蹤贞绵,失蹤者是張志新(化名)和其女友劉穎嫡意,沒想到半個月后橘券,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,400評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡竖伯,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評論 2 323
  • 正文 我和宋清朗相戀三年章母,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了母蛛。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 37,997評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡乳怎,死狀恐怖彩郊,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情蚪缀,我是刑警寧澤秫逝,帶...
    沈念sama閱讀 33,646評論 4 322
  • 正文 年R本政府宣布,位于F島的核電站询枚,受9級特大地震影響违帆,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜金蜀,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評論 3 307
  • 文/蒙蒙 一刷后、第九天 我趴在偏房一處隱蔽的房頂上張望的畴。 院中可真熱鬧,春花似錦尝胆、人聲如沸丧裁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽渣慕。三九已至,卻和暖如春抱慌,著一層夾襖步出監(jiān)牢的瞬間逊桦,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評論 1 260
  • 我被黑心中介騙來泰國打工抑进, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留强经,地道東北人。 一個月前我還...
    沈念sama閱讀 45,423評論 2 352
  • 正文 我出身青樓寺渗,卻偏偏與公主長得像匿情,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子信殊,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評論 2 345

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

  • 內(nèi)容抽屜菜單ListViewWebViewSwitchButton按鈕點(diǎn)贊按鈕進(jìn)度條TabLayout圖標(biāo)下拉刷新...
    皇小弟閱讀 46,708評論 22 664
  • CoordinatorLayout與滾動的處理 CoordinatorLayout實(shí)現(xiàn)了多種Material De...
    cxm11閱讀 6,567評論 1 15
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 171,499評論 25 707
  • 我盼著你長大炬称, 長大后能露出沉穩(wěn)的微笑, 迷人時(shí)甚至毫無自覺涡拘。 但后來玲躯, 我盼望你老去, 老去時(shí)再無精力去流浪鳄乏, ...
    a2c8f9da6aab閱讀 171評論 0 0
  • 用鉛筆畫底稿跷车。用時(shí)25分鐘。 用簽字筆勾線橱野。用時(shí)五分鐘朽缴。 涂色。用時(shí)55分鐘水援。 遺憾的是密强,我用的輝柏嘉彩鉛只有48...
    林上雪閱讀 560評論 3 12