Material Theme提供了一下功能:
1、系統widgets可以設置調色板
2、系統widgets的觸摸反饋
3、Activity過渡動畫
你可以根據你品牌的色彩來定義Material Theme,可以使用Material Theme的色彩爲status bar、action bar着色。參考下圖。
系統Widgets有新的設計和觸摸動畫,你也可以在自己的應用中自定義色彩調色板、觸摸反饋動畫、Activity過渡。
Material Theme的定義如下:
@android:style/Theme.Material
(dark version)@android:style/Theme.Material.Light
(light version)@android:style/Theme.Material.Light.DarkActionBar
你可以使用一系列的material styles,查看 Android.R.style
參考。
Customize the Color Palette
自定義主題的基礎顏色,以適應你的品牌,使用Theme屬性自定義顏色,Theme繼承自Material Theme。
- <resources>
- <!– inherit from the material theme –>
- <style name=“AppTheme” parent=“android:Theme.Material”>
- <!– Main theme colors –>
- <!– your app’s branding color (for the app bar) –>
- <item name=“android:colorPrimary”>@color/primary</item>
- <!– darker variant of colorPrimary (for status bar, 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>
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app's branding color (for the app bar) -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant of colorPrimary (for status bar, 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>
Customize the Status and Navigation Bar
使用material theme可以簡單的自己定製status bar,可以讓status bar適應你的產品,這個在iOS中也是可以實現的。可以設置android:statusBarColor屬性來設置status bar的顏色。前面看到的
android:colorPrimaryDark
會默認設置爲status bar的顏色。
Java方法中可以使用Window.setStatusBarColor方法改變status bar來改變色彩。
Theme Individual Views
XML佈局中定義的元素可以指定android主題屬性。就是可以爲你的views在Theme中聲明各種屬性的值。
這一點,說的最主要的是可以改變status bar的顏色,以前的版本是不可以的。