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

來源:互聯網
上載者:User

標籤:android   material design   

本人所有文章首先發佈於個人部落格,歡迎關注,地址: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


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,但是由於低版本不支援沈浸式狀態列,有一些效果還是無法實現。

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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.