本人所有文章首先發(fā)布于個(gè)人博客院究,歡迎關(guān)注,地址:http://blog.isming.me
昨天正式發(fā)布了android 5,同時(shí)android developer網(wǎng)站也更新了,增加了創(chuàng)建Material Design風(fēng)格的Android應(yīng)用指南,也更新了Support Library,在support library增加了一些Material Design風(fēng)格的控件和動(dòng)畫等爱咬,這里給大家簡單介紹一下怎樣開發(fā)material design風(fēng)格的Android應(yīng)用。
android 5使用Material Design風(fēng)格
android提供了三種Material Design風(fēng)格Theme衅胀。
分別是:
@android:style/Theme.Material (dark version)
@android:style/Theme.Material.Light (light version)
@android:style/Theme.Material.Light.DarkActionBar
![Light material theme](http://ourhfuu.qiniudn.com/theme_MaterialLight.png)
Light material theme
![Dark material theme](http://ourhfuu.qiniudn.com/theme_MaterialDark.png)
Dark material theme
我們可以以這三個(gè)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>
我們可以修改每個(gè)位置的字或者背景的顏色,每個(gè)位置的名字如下圖所示:
![Customizing the material theme](http://ourhfuu.qiniudn.com/material_theme_colors.png)
我就簡單的介紹一下迹卢,更具體的自己探索吧辽故。
較低版本使用Material Design風(fēng)格
要在較低版本上面使用Material Design風(fēng)格,則需要使用最新的support library(version 21)腐碱,可以直接把項(xiàng)目引入工程誊垢,或者使用gradle構(gòu)建,增加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增加一個(gè)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>
這樣可以同樣實(shí)現(xiàn)很多的地方是Material Design,但是由于低版本不支持沉浸式狀態(tài)欄,有一些效果還是無法實(shí)現(xiàn)谋作。
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/,轉(zhuǎn)載請(qǐng)注明出處寂殉。