Material主題的使用

http://developer.android.com/training/material/theme.html

Material主題帶來的效果體現在以下幾個方面:

  • System widgets that let you set their color palette(調色板)
  • 系統控件(部件)的觸屏反饋動畫
  • Activity跳轉動畫
當然,我們可以在app中對color palette、觸屏反饋動畫和Activity跳轉動畫進行自定義。 

系統提供的主題樣式:

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


Note: 這些Material主題效果只支持在 Android 5.0 (API level 21)的設備上使用. 兼容包v7 appcompat library(兼容5.0以下的設備)只支持部分的樣式和控件效果,詳情: Maintaining Compatibility.

自定義Color Palette


<resources>
  <!-- 繼承自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>


colorPrimaryDark - 這是app中最黑的基本色,主要用來做notification bar的背景.

colorPrimary - 這是app的基本顏色,將用作toolbar的背景色

textColorPrimary - 文本顏色,用於toolbar的標題

windowBackground - app默認的背景顏色

navigationBarColor - 這個顏色定義了navigation bar頁腳的背景色.


自定義狀態欄

 
 使用屬性android:statusBarColor
 用法:
<resources>
  <!-- 繼承自material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   ... -->
    <item name="android:statusBarColor">自定義顏色值</item>
    <!--  ... -->
  </style>
</resources>



發佈了42 篇原創文章 · 獲贊 90 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章