建立Material Design風格的Android應用--應用主題

昨天正式發佈了android 5,同時android developer網站也更新了,增長了建立Material Design風格的Android應用指南,也更新了Support Library,在support library增長了一些Material Design風格的控件和動畫等,這裏給你們簡單介紹一下怎樣開發material design風格的Android應用。html

android 5使用Material Design風格

android提供了三種Material Design風格Theme。java

分別是:android

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

Light material theme

Light material themeapp

Dark material theme

Dark material theme佈局

咱們能夠以這三個Theme來定義咱們的Theme,好比:gradle

<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

我就簡單的介紹一下,更具體的本身探索吧。網站

較低版本使用Material Design風格

要在較低版本上面使用Material Design風格,則須要使用最新的support library(version 21),能夠直接把項目引入工程,或者使用gradle構建,增長compile dependency:code

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,以下:xml

<!-- 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/,轉載請註明出處。

相關文章
相關標籤/搜索