Material Design系列第三篇——Using the Material Theme

Using the Material Theme

This lesson teaches you to

  1. Customize the Color Palette
  2. Customize the Status Bar
  3. Theme Individual Views

You should also read

The new material theme provides:

  • System widgets that let you set their color palette
  • Touch feedback animations for the system widgets
  • Activity transition animations

You can customize the look of the material theme according to your brand identity with a color palette you control. You can tint the action bar and the status bar using theme attributes, as shown in Figure 3.

The system widgets have a new design and touch feedback animations. You can customize the color palette, the touch feedback animations, and the activity transitions for your app.

The material theme is defined as:

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

For a list of material styles that you can use, see the API reference for R.style.

Figure 1. Dark material theme

Figure 2. Light material theme

Note: The material theme is only available in Android 5.0 (API level 21) and
above. The v7 Support Libraries
provide themes with material design styles for some widgets and support for customizing the color
palette. For more information, see
Maintaining Compatibility.

Customize the Color Palette



To customize the theme‘s base colors to fit your brand, define
your custom colors using theme attributes when you inherit from the material theme:

<resources>  <!-- inherit from the material theme -->  <stylename="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>

Figure 3. Customizing the material theme.

Customize the Status Bar



The material theme lets you easily customize the status bar, so you can specify a color that fits your brand and provides enough contrast to show the white status icons. To set a custom color for the status bar, use the android:statusBarColor attribute when you extend the material theme. By default, android:statusBarColor inherits the value of android:colorPrimaryDark.

You can also draw behind the status bar yourself. For example, if you want to show the status bar transparently over a photo, with a subtle dark gradient to ensure the white status icons are visible. To do so, set the android:statusBarColor attribute to @android:color/transparent and adjust the window flags as required. You can also use the Window.setStatusBarColor() method for animations or fading.

Note: The status bar should almost always have a clear delineation from the primary toolbar, except for cases where you show edge-to-edge rich imagery or media content behind these bars and when you use a gradient to ensure that the icons are still visible.

When you customize the navigation and status bars, either make them both transparent or modify only the status bar. The navigation bar should remain black in all other cases.

Theme Individual Views



Elements in XML layout definitions can specify the android:theme attribute, which references a theme resource. This attribute modifies the theme for the element and any child elements, which is useful for altering theme color palettes in a specific portion of an interface.

时间: 2024-11-06 07:34:58

Material Design系列第三篇——Using the Material Theme的相关文章

Material Design系列第四篇——Using the Material Theme

Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Customize View Shadows and Outlines Clip Views You should also read Material design specification Material design on Android Material design introduces elev

Material Design系列第六篇——Defining Custom Animations

Defining Custom Animations This lesson teaches you to Customize Touch Feedback Use the Reveal Effect Customize Activity Transitions Animate View State Changes Animate Vector Drawables You should also read Material design specification Material design

Material Design系列第五篇——Working with Drawables

Working with Drawables This lesson teaches you to Tint Drawable Resources Extract Prominent Colors from an Image Create Vector Drawables You should also read Material design specification Material design on Android The following capabilities for draw

Material Design系列第七篇——Maintaining Compatibility

Maintaining Compatibility This lesson teaches you to Define Alternative Styles Provide Alternative Layouts Use the Support Library Check the System Version You should also read Material design specification Material design on Android Some material de

Android Material Design系列之主题样式介绍说明

今天这篇文章应该算是Material Design系列的补充篇,因为这篇文章本来应该放到前面讲的,因为讲的是主题嘛,对于一些状态和颜色的介绍,因为我们一新建一个项目时,系统自带了三个属性的颜色,现在就重点介绍这三个颜色属性的意义和作用.讲明白这个,留着以后讲别的用. 最常用的三个颜色属性 colorPrimary colorPrimaryDark colorAccent 这三个分别代表什么意思呢? colorPrimaryDark 是状态栏底色 colorPrimary 如果你不手动自己去修改t

Material Design系列,自定义Behavior支持所有View

Material Design系列,自定义Behavior支持所有View 版权声明:转载必须注明本文转自严振杰的博客: http://blog.csdn.net/yanzhenjie1003 友情连接: Material Design博客专栏 系列博客: 1. Material Design系列,Behavior之BottomSheetBehavior与BottomSheetDialog 2. Material Design系列,Behavior之SwipeDismissBehavior 3.

Material Design系列第一篇——Creating Apps with Material Design

Creating Apps with Material Design Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. To use material design in your Android apps, follow the guidelines described in the material design s

Material Design系列第二篇——Getting Started

Getting Started This lesson teaches you to Apply the Material Theme Design Your Layouts Specify Elevation in Your Views Create Lists and Cards Customize Your Animations You should also read Material design specification Material design on Android To

深入理解javascript函数系列第三篇

前面的话 函数是javascript中特殊的对象,可以拥有属性和方法,就像普通的对象拥有属性和方法一样.甚至可以用Function()构造函数来创建新的函数对象.本文是深入理解javascript函数系列第三篇--属性和方法 属性 [length属性] 函数系列第二篇中介绍过,arguments对象的length属性表示实参个数,而函数的length属性则表示形参个数 function add(x,y){ console.log(arguments.length)//3 console.log(