我最近在做公司項目的一個新頁面,研究了一下,發現要使用到5.0的新控件。由于之前種種原因,對這塊是一知半解,趁這次機會系統的學習一下Material Design
設計和推出的這些控件。
Material Design 是2014年隨著Android 5.0
系統被Google
推出的全新的設計語言,比起之前Android系統的UI,Material Design
顏色更鮮艷,動畫效果更突出,UI更是內置了實時陰影,已經在不同屏幕之間切換的hero
元素。
PS:大神鴻洋的博客 http://blog.csdn.net/lmj623565791/article/details/45303349對我幫助很多,本篇文章也是在此基礎上作的總結,在此感謝。
Material Design Theme 介紹
隨著Android SDK的更新,在Android Studio中新建EmptyActivity,默認繼承的是AppCompatActivity
。打開styles.xml
,會發現項目默認使用的主題是Theme.AppCompat.XXX
。其實這就是Material Design
主題之一.
Material Design
主題主要有三種:
- Theme.AppCompat.
- Theme.AppCompat.Light
- Theme.AppCompat.Light.DarkActionBar
當前并不僅限于這三種,例如當你你不想使用ActionBar
的時候,可以使用Theme.AppCompat.NoActionBar
.當然你也可以使用如下這種方式:
//在AppTheme中加入如下兩行
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
推薦使用第一種方式。
自定義Material Design 主題
Google 在 Android 5.0 之后,開放了自定義狀態欄的功能,是App更好的與手機融為一體。
- colorPrimary 對應ActionBar顏色
- colorPrimaryDark 對應狀態欄的顏色
- cloorAccent 對應EditText、RadioButton、CheckBox等選中時的顏色
測試如下:*
- 代碼
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> // ActionBar背景色
<item name="colorPrimaryDark">#dfdf30</item> // 狀態欄顏色
<item name="colorAccent">#df5630</item> // 被選中顏色EditText,Chebox,RadioButton
</style>
- 效果
屏幕截圖
測試機為6.0模擬器
本章小結
本章主要介紹了Matrerial Design
的一些特性,已經Material Design Theme
一些重要的屬性。一篇文章寫下來,有點撥開云霧的感覺,托大神的福,我省了不少的力氣,再次感謝。