創建Material Design風格的Android應用

velocity123 8年前發布 | 13K 次閱讀 Android開發 移動開發

 昨天正式發布了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

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

我就簡單的介紹一下,更具體的自己探索吧。

較低版本使用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://blog.isming.me/2014/10/18/creating-android-app-with-material-design-one-theme/


 本文由用戶 velocity123 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!