初识Android Material Design-新闻详情

初识Android Material Design


发布时间:2016-09-22责任编辑:朱明 浏览:1459


随着Android的发展,Android开发工具由原来的Eclipse逐渐替换为Android Studio,Google并在2014年的IO大会上带来了Material Design设计风格,从根本上规范了Android的开发。开发中引入Material Design很简单,只需要通过Gradle引入Android Design Support Library即可:

compile 'com.android.support:design:23.2.1'
Android Design Support Library提供了常用的Meterial Design风格的控件,下面就常用的几个作一下介绍:
1:抽屉导航DrawerLayout、NavigationView

不少APP都有侧滑菜单功能,与之前的实现方法相比,引入DrawerLayout侧滑菜单很简单:

<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:id"@+id/drawer_layout"
   
android:layout_width"match_parent"
   
android:layout_height"match_parent"
   
android:fitsSystemWindows"true"
   
tools:openDrawer"start">

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

    <
android.support.design.widget.NavigationView
       
android:id"@+id/nav_view"
       
android:layout_width"wrap_content"
       
android:layout_height"match_parent"
       
android:layout_gravity"start"
       
android:fitsSystemWindows"true"
       
app:headerLayout"@layout/nav_header_main"
       
app:menu"@menu/activity_main_drawer" />

android.support.v4.widget.DrawerLayout>
 
DrawerLayout作为根标签,NavigationView作为内容标签,其中NavigationView又包括headerLayout和menu两个Layout,前一个表示侧滑菜单的头部,menu表示菜单Layout。

2TabLayout

TabLayout和ViewPager组合可以简单美观的进行页面切换。布局如下:
 
<xml version"1.0" encoding"utf-8">
<LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"
   
android:layout_width"match_parent"
   
android:layout_height"match_parent"
   
android:orientation"vertical"
   
android:background"@android:color/white">

    <
android.support.design.widget.TabLayout
       
android:id"@+id/second_job_tablayout"
       
android:layout_width"match_parent"
       
android:layout_height"@dimen/head_height">
    android.support.design.widget.TabLayout>

    <
android.support.v4.view.ViewPager
       
android:id"@+id/secondhand_job_viewPager"
       
android:layout_width"match_parent"
       
android:layout_height"match_parent">
    android.support.v4.view.ViewPager>
LinearLayout>
 
在Java中的使用方法如下:
      
3:SnackBar
SnackBar相当于升级版的Toast,SnackBar相比Toast更加美观,并且功能更多,SnackBar有如下函数:

l  dismiss() Snackbar消失

l  getDuration() 得到显示时长

l  make(View view, int resId, int duration) 创建 Snackbar

l  make(View view, CharSequence text, int duration) 创建 Snackbar

l  setAction(int resId, View.OnClickListener listener) 对Snackbar 设置单击时间,这里的单击时间不是作用于整个 Snackbar,还是作用于你所设置的这个字段,也就是这个resId 

l  setAction(CharSequence text, View.OnClickListener listener)和上面一样

l  setActionTextColor(ColorStateList colors) 设置动作字的颜色,就是对上面的setAction 中文字颜色的设置

l  setActionTextColor(int color) 和上面一样

l  setDuration(int duration) 设置 Snackbar 显示时长

l  setText(int resId) 更新 Snackbar 中的文本

l  setText(CharSequence message) 和上面一样

l  show() 显示 Snackbar

显示效果如下:

除了上面这些,Android Support Design Library还包括了一些常用的控件,详细见如下网站:
 
相关网站:
https://material.google.com/
https://www.sitepoint.com/material-design-android-design-support-library/

 

 

诚信工作室   供稿