美文网首页一起来学习Material Design
Material Design重新学系列 - 1.简介以及主题样

Material Design重新学系列 - 1.简介以及主题样

作者: zsj1225 | 来源:发表于2017-06-26 22:42 被阅读118次

    Material Design

    Material Design简介

    Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干净的排版和简单的布局,以此来突出内容。

    Material Design对排版、材质、配色、光效、间距、文字大小、交互方式、动画轨迹都做出了建议,以帮助设计者设计出符合Material Design风格的应用。

    更多详情请见Material Design文档:

    官方版:https://developer.android.com/design/index.html

    国内有翻译网站: http://wiki.jikexueyuan.com/project/material-design/material-design-intro/introduction.html

    Material Design使用

    作为我们开发者,最关心的还是如何在项目中使用Material Design风格:

    1. 设置应用的 targetSdkVersiontargetSdkVersion 为21
    2. 在values目录下的style资源文件中创建一个style,让其继承自 android:Theme.Material等Material样式
    3. 在AndroidManifest中指定应用的主题或者Activity的主题为我们设定的样式

    谷歌官方我们提供了三种配色风格的Material Design样式:

    1. 黑色主题 Theme.Material
    2. 明亮主题 Theme.Material.Light
    3. 明亮主题黑色ActionBar Theme.Material.Light.DarkActionBar

    当然我们也可以继承系统提供的Material Design样式,再进行配色修改:

    image.png

    常见的属性:

    1. android:colorPrimaryDark 应用的主要暗色调,statusBarColor默认使用该颜色
    2. android:statusBarColor 状态栏颜色,默认使用colorPrimaryDark
    3. android:colorPrimary 应用的主要色调,actionBar默认使用该颜色
    4. android:windowBackground 窗口背景颜色
    5. android:navigationBarColor 底部栏颜色
    6. android:colorForeground 应用的前景色,ListView的分割线,switch滑动区默认使用该颜色
    7. android:colorBackground 应用的背景色,popMenu的背景默认使用该颜色
    8. android:colorAccent 一般控件的选种效果默认采用该颜色
    9. android:colorControlNormal 控件的默认色调
    10. android:colorControlHighlight 控件按压时的色调
    11. android:colorControlActivated 控件选中时的颜色,默认使用colorAccent
    12. android:colorButtonNormal 默认按钮的背景颜色
    13. android:textColor Button,textView的文字颜色
    14. android:textColorPrimaryDisableOnly RadioButton checkbox等控件的文字
    15. android:textColorPrimary 应用的主要文字颜色,actionBar的标题文字默认使用该颜色

    Material Design兼容性

    Material Design主题只有在API级别为21以上才可使用,在v7支持库中提供了部分控件的Material Design主题样式,如果想使应用在android的所有版本上都能统一风格,我们可以对控件效果做自定义或者使用一些第三方的兼容包。目前最有效的做法是针对21版本创建value-21资源目录,使用Material Design风格主题,在其他版本使用v7的Theme.AppCompat.Light风格主题。

    Material Design例子 - 更换主题

    @Override
        public void onClick(View v) {
            //1.设置主题,2重新启动,3.使用新主题
            mTheme = R.style.MyTheme;
    
            //取消跳转动画。
            overridePendingTransition(0, 0);
            finish();
            //重新启动
            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            overridePendingTransition(0, 0);
            startActivity(intent);
        }
    

    demo地址:
    https://github.com/zsj1225/Md_Demo 中的Md_ChangeTheme

    相关文章

      网友评论

      • _沉:写的好,学习了

      本文标题:Material Design重新学系列 - 1.简介以及主题样

      本文链接:https://www.haomeiwen.com/subject/zoqscxtx.html