创建Material Design风格的Android应用--应用主题

本人所有文章首先发布于个人博客,欢迎关注,地址:http://blog.isming.me

昨天正式发布了android 5,同时android developer网站也更新了,增加了创建Material Design风格的Android应用指南,也更新了Support Library,在support library增加了一些Material Design风格的控件和动画等,这里给大家简单介绍一下怎样开发material design风格的Android应用。

android 5使用Material Design风格

android提供了三种Material Design风格Theme。

分别是:

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

Light material theme

Dark material theme
Dark material theme

Dark material theme

我们可以以这三个Theme来定义我们的Theme,比如:

<resources>
 <!-- inherit from the material theme -->
 <style name="AppTheme" parent="android:Theme.Material">
   <!-- Main theme colors -->
   <!--   your app branding color for the app bar -->
   <item name="android:colorPrimary">@color/primary</item>
   <!--   darker variant for the status bar and 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>

我们可以修改每个位置的字或者背景的颜色,每个位置的名字如下图所示:

Customizing the material theme
Customizing the material theme

我就简单的介绍一下,更具体的自己探索吧。

较低版本使用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,但是由于低版本不支持沉浸式状态栏,有一些效果还是无法实现。

PS:就写这么多吧。下次写使用CardView 和RecyclerView。做Material Design的List 和Card布局。 (我英文不好,可能有些地方也理解的不好。)

参考:http://developer.android.com/training/material/theme.html

原文地址:http://blog.isming.me/2014/10/18/creating-android-app-with-material-design-one-theme/,转载请注明出处。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,675评论 25 709
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,642评论 2 45
  • 1、 github排名 https://github.com/trending,github搜索:https://...
    GB_speak阅读 9,944评论 2 117
  • 这条街到了晚上就会变得灯火通明,仿佛整条街的热情都在这寂寞的夜里消耗殆尽。 其中一个酒吧的安全通道里,昏黄的灯光忽...
    霍小柒阅读 562评论 2 3
  • 西叶的胳膊肘支撑着脑袋,无聊地张望着。眯着眼细细观察往来的人群,只盼着看出哪一个与众不同的人有着一身祥瑞之气,便待...
    明公子阅读 306评论 0 1