Android:Material Design(一) 概述
Android:Material Design(二) Material主题
Android:Material Design(三) 动画
Android:Material Design(四) UI控件
Android:Material Design(五) 视图和阴影
Android:Material Design(六) 使用Drawable
Android:Material Design(七) 兼容性

Material Theme只能应用在Android L(api 21)版本。所以想要尝试使用Material Theme请先搭建环境。

1.使用Material Theme

应用Material主题很简单,只需要修改res/values/styles.xml(v 21)文件,使其继承android:Theme.Material。如下:

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="AppTheme" parent="android:Theme.Material"> </style></resources>

或者在AndroidManifest.xml中直接设置主题:

android:theme="@android:style/Theme.Material.Light"

2.自定义Material Theme

@android:style/Theme.Material (dark version)
@android:style/Theme.Material.Light (light version)
@android:style/Theme.Material.Light.DarkActionBar

当然除了这3种,还有其他的,想要了解的,请查看 android.R.style

3.自定义颜色基调(color palette)

material可以根据自定的品牌风格,自定义主题的基础色调,如下(参考下方图片)

<?xml version="1.0" encoding="utf-8"?><resources>   <!-- inherit from the material theme -->   <style name="AppTheme" parent="android:Theme.Material"> <!-- Main theme colors --> <!-- your app's branding color (for the app bar) --> <item name="android:colorPrimary">@color/primary</item> <!-- darker variant of colorPrimary (for status bar, contextual app bars) --> <item name="android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style> </resources>

4.自定义状态条和导航条

使用Material Theme可以简单的自己定制状态条,可以让状态条适应你的产品。可以设置android:statusBarColor属性来设置状态条的颜色。前面看到的android:colorPrimaryDark会默认设置为status bar的颜色。
java方法中可以使用Window.setStatusBarColor方法改变status bar来改变色彩。
如果你想在照片上能明显的显示状态栏,用一个细微的黑色渐变来确保白色状态栏图标可见。为此,设置android:statusBarColor属性为@android:color/transparent,并根据需要调整Window的flags。对于动画或消退(fading),你也可以使用Window.setStatusBarColor()方法
当你自定义导航和状态栏时,要么使它们都透明,要么只修改状态栏。导航栏在其他所有情况下必须保持黑色。

5.较低版本使用Material Design风格

由于Material Theme只可以在Android L Developer Preview中使用。
所以在低版本使用的话就需要为其另设一套主题:
在老版本使用一套主题 res/values/styles.xml,在新版本使用Material主题res/values-v21/styles.xml.
较低版本使用Material Design风格
要在较低版本上面使用Material Design风格,则需要使用最新的support library(version 21),可以直接把项目引入工程,或者使用gradle构建,增加compile dependency:

dependencies { compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:recyclerview-v7:+' }

将上面的AppTheme style放到res/values-v21/style.xml,再res/values/style.xml增加一个AppTheme,如下:

<!-- extend one of the Theme.AppCompat themes --><style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorPrimary">@color/material_blue_500</item> <item name="colorPrimaryDark">@color/material_blue_700</item> <item name="colorAccent">@color/material_green_A200</item> </style>

这样可以同样实现很多的地方是Material Design,但是由于低版本不支持沉浸式状态栏,有一些效果还是无法实现。

参考资料

http://www.open-open.com/lib/view/open1416664325648.html

更多相关文章

  1. Android(安卓)SDK Android(安卓)NDK 官方下载地址(更新加版本号
  2. [Android]Android布局文件中的android:id="@*"属性使用方法汇总
  3. [Android]Android布局文件中的android:id="@*"属性使用方法汇总
  4. android中自带的主题(theme)的集
  5. android 中系统自带的主题与样式(theme and style)
  6. android 中系统自带的主题与样式(theme and style)
  7. android 中系统自带的主题与样式(theme and style)
  8. android系统自带的主题与样式(theme and style)
  9. 【Android】系统自带的主题与样式(theme and style)

随机推荐

  1. 商品管理器实例,node基础知识(包安装、删除
  2. 如何学好素描基础?新手自学素描技巧!
  3. 闭包 访问器 js dom
  4. Android基础知识及线性布局介绍
  5. 2022年最新phpStorm激活插件,可激活2021.3
  6. 这些node开源工具你值得拥有(上)
  7. php.ini 配置文件的深入解析
  8. Oracle 9i产品文档
  9. 实现core文件自动生成配置文件的方法
  10. RHEL6.5下JDK1.8安装教程