Theme

material主题可以定义为如下形式:

  • @android:style/Theme.Material
  • @android:style/Theme.Material.Light
  • @android:style/Theme.Material.Light.DarkActionBar

我们可以在vlues-v21中的styles.xml文件中继承这些主题,然后定制一些属性。在v21中可以做如下修改

<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>

这里设置了几个主题颜色

注:

<item name="android:colorAccent">#00FF00</item>

colorAccent是设置像是CheckBox的颜色

接下来,我们主要来看看在低版本中应该如何设置

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimaryDark">#3367d6</color>
<color name="colorPrimary">#4285f4</color>
<color name="windowBackground">#eeeeee</color> </resources>

styles.xml

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

    <!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here. -->
</style> <!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/primary_material_light</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style> </resources>

这样我们就设置好了类似于下面的效果:

现在我们终于在高版本上能改变status bar的颜色了,这个在以前是不可能的。话说4.4也支持这个。下面我们来详细看看在低版本中我们如何让自己的主题完美工作。

1.首先继承一个Compat的主题

在compat包中我们可以看到有很多主题,我们找到给activity用的,发现也就下面红框里这么几个,看名字就能知道是什么了。

<resources>

    <!-- Themes in the "Theme.AppCompat" family will contain an action bar by default.
If Holo themes are available on the current platform version they will be used.
A limited Holo-styled action bar will be provided on platform versions older
than 3.0. (API 11) These theme declarations contain any version-independent specification. Items
that need to vary based on platform version should be defined in the corresponding
"Theme.Base" theme. --> <!-- Platform-independent theme providing an action bar in a dark-themed activity. -->
<style name="Theme.AppCompat" parent="Base.Theme.AppCompat" /> <!-- Platform-independent theme providing an action bar in a light-themed activity. -->
<style name="Theme.AppCompat.Light" parent="Base.Theme.AppCompat.Light" /> <!-- Platform-independent theme providing an action bar in a dark-themed activity. -->
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" /> <style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style> <style name="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>

继承Theme.AppCompat,效果↓

  

继承Theme.AppCompat.Light效果↓

  

继承Theme.AppCompat.Light.DarkActionBar效果↓

  

此外,在Android的4.4添加了View.SYSTEM_UI_FLAG_IMMERSIVEView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY。这两个标记可以实现所谓的沉浸式状态栏,个人感觉翻译的不好,应该叫做一种状态栏模式。这些标记的作用是在应用(比如视频)在需要全屏时抹去状态栏,但是在退出视频时又能回来。准确来说是叫:ImmersiveMode或者是Translucent Modes,总之是一种模式。

详细可以看这篇文章:http://www.tuicool.com/articles/RVRneq

在Smooth中已经实现了4.4上的效果,具体如下:

  

总之呢,在之前的版本上状态栏上面还是不能由我们随意定制的,4.4除外。但也有好消息,那就是ActionBar可以被我们再一次定制了,而且可以兼容之前的设备,利用的是ToolBar这个新控件。关于Toolbar的使用,我们以后会讲到。

Material Designer的低版本兼容实现(二)—— Theme的更多相关文章

  1. Material Designer的低版本兼容实现(一)—— 简介 & 目录

    很长一段时间没写东西了,其实是因为最近在研究Material Designer这个东西,熬夜熬的身体也不是很好了.所以就偷懒没写东西,这回开的这个系列文章是讲如何将Material Designer在 ...

  2. Material Designer的低版本兼容实现(五)—— ActivityOptionsCompat

    extends:http://www.cnblogs.com/tianzhijiexian/p/4087917.html 本文是对API中的方法做了介绍,如果想要看如何让这些方法兼容4.x或2.x可以 ...

  3. Material Designer的低版本兼容实现(三)——Color

    在Material Designer中,色彩再一次被摆到了重要的位置上.官方文档中竟然给出了500种配色方案进行选择.就是为了给不同的手机.电视.手表上带来一直的用户体验. 更多用于控制色彩的属性,可 ...

  4. Material Designer的低版本兼容实现(十)—— CheckBox & RadioButton

    ChekBox的用途我们就不必多说了,算是一个很古老的控件了,何其类似的还有RadioButton,这个东西因为我目前还没写出来,所以用了别人的一个lib,这下面会说到.顺便说一句,如果你的app是在 ...

  5. Material Designer的低版本兼容实现(十二)—— Slider or SeekBar

    Slider,我更喜欢叫他SeekBar,其实是一个东西啦,就是拖动条.5.0的拖动条和4.x上的HOLO风格完全不同,平添了一些精致.此外还加入了数值指示器,让用户在滑动的时候就能知道现在到了什么位 ...

  6. Material Designer的低版本兼容实现(十四)—— CardView

    今天说的又是一个5.0中才有的新控件——CardView(卡片视图).这个东东其实我们早就见过了,无论是微博还是人人客户端,它都有出现.通常我们都是通过自定义一个背景图片,然后通过给layout进行设 ...

  7. Material Designer的低版本兼容实现(十三)—— ProgressBar

    进度条我们都很常见了,新的设计规范中提出了各式各样的进度条,本篇就会介绍大部分进度条的实现.实现方式和规范的示例图可能略有差异,还是那句话根据具体需求进行改变吧. PS:本文较长 参考文档:http: ...

  8. Material Designer的低版本兼容实现(十一)—— Switch

    5.0中的switch和之前完全不同了,漂亮不漂亮咱们另说,总之4.x上是没有这样的效果了.实现方式有两种,一种是用这个兼容包来做类似的效果,一种是用传统的checkbox来代替.我感觉兼容包的效果是 ...

  9. Material Designer的低版本兼容实现(九)—— Float Button & Small Float Button

    5.0一个新特性就是出现了这么一个圆形的悬浮指示按钮,这个按钮可以用来体现一个全局的重要功能,比如添加账户什么的.这个按钮有两种大小,一种是正常的按钮大小,一种是小型的按钮.官方文档中介绍的是小心的按 ...

随机推荐

  1. 第二届CCF软件能力认证

    1. 相邻数对 问题描述 给定n个不同的整数,问这些数中有多少对整数,它们的值正好相差1. 输入格式 输入的第一行包含一个整数n,表示给定整数的个数. 第二行包含所给定的n个整数. 输出格式 输出一个 ...

  2. 使用nginx统一代理dashboard,grafana,Prometheus二级目录访问

    k8s上的这些管理工具必不可少,可以统一在nginx下的二级目录下. ingress是好,但我们不方便使用内部域名,相信么...:) 一,prometheus改造 在prometheus的deploy ...

  3. 【LOJ】#2118. 「HEOI2015」兔子与樱花

    题解 怎么觉得都像树dp,不像贪心 但是树dp确实做不了 把每个节点的值设置为樱花+儿子数 把儿子合并到父亲上就是父亲的剩余容量加上儿子的值-1 每次在父亲的时候将儿子的值排序然后能加就加上 因为儿子 ...

  4. 针对LDAP安装web接口,进行管理

    1. 通过SSH连接LDAP服务器 2. 安装phpLDAPadmin运行以下命令. $ sudo apt-get install phpldapadmin 3. 配置phpLDAPadmin. $ ...

  5. 000 Jquery的Hello World程序

    1.介绍Jquery 2.简介 3.新建一个静态项目,并粘贴jquery库 4.程序 <!DOCTYPE html> <html> <head> <meta ...

  6. oj提交时常见错误归纳

    Presentation Error: 常见的PE错误应该有以下的几种情况: 每行输出之后有空行 每两行输出之间有空行 一行中,每个输出数字(或字符串,等)之间有空格 一行中,每个输出数字(或字符串, ...

  7. js冲刺一下

    js中__proto__和prototype的区别和关系 1.对象有属性__proto__,指向该对象的构造函数的原型对象. 2.方法除了有属性__proto__,还有属性prototype,prot ...

  8. Nuget 下载过慢的解决办法

    设置依赖项行为为忽略,文件冲突操作为忽略

  9. DIV+javascript实现首尾相连循环滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog

    DELPHI - How to use opendialog1 for choosing a folder? On Vista and up you can show a more modern lo ...