Android:Material design的一些理解 - MrWu94/AndroidNote GitHub Wiki

Material Theme

使用Material主题:

Material主题只能应用在Android L版本。
应用Material主题很简单,只需要修改res/values/styles.xml文件,使其继承android:Theme.Material。如下:

<!-- res/values/styles.xml -->  
<resources>  
  <!-- your app's theme inherits from the Material theme -->  
  <style name="AppTheme" parent="android:Theme.Material">  
    <!-- theme customizations -->  
  </style>  
</resources>  

或者在AndroidManifest.xml中直接设置主题:

android:theme="@android:style/Theme.Material.Light" 

对于其他主题风格可以参考API文档!(android.R.style)[https://developer.android.com/reference/android/R.style.html?hl=zh-cn]

自定义Material主题:

material主题可以定义为如下形式:
@android:style/Theme.Material(深色版本)
@android:style/Theme.Material.Light(浅色版本)
@android:style/Theme.Material.Light.DarkActionBar

注意:材料主题仅在 Android 5.0(API 级别 21)及更高版本中提供。 !(v7支持内容库)[https://developer.android.com/tools/support-library/features.html?hl=zh-cn#v7]为一些小组件提供附带 Material Design 风格的主题,同时为配色工具定制提供支持。 如果要了解更多信息,请参阅 保持兼容性。

自定义颜色基调(color palette)

material可以根据自定的品牌风格,自定义主题的基础色调,如下(参考下方图片):

<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>  

自定义状态条和导航条:

material还允许你轻松的自定义状态条和导航条的颜色。 可以使用如下属性(参考下方图片): android:statusBarColor,Window.setStatusBarColor

兼容性:

由于Material Theme只可以在Android L Developer Preview中使用。 所以在低版本使用的话就需要为其另设一套主题: 在老版本使用一套主题 res/values/styles.xml,在新版本使用Material主题res/values-v21/styles.xml.

参考资料:https://developer.android.com/training/material/theme.html?hl=zh-cn

⚠️ **GitHub.com Fallback** ⚠️