創建Material Design風格的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
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>
我們可以修改每個位置的字或者背景的顏色,每個位置的名字如下圖所示:
我就簡單的介紹一下,更具體的自己探索吧。
較低版本使用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/,轉載請注明出處。