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
Some material design features like the material theme and custom activity transitions are only available on Android 5.0 (API level 21) and above. However, you can design your apps to make use of these features when running on devices that support material design and still be compatible with devices running previous releases of Android.
Define Alternative Styles
You can configure your app to use the material theme on devices that support it and revert to an older theme on devices running earlier versions of Android:
- Define a theme that inherits from an older theme (like Holo) in
res/values/styles.xml
. - Define a theme with the same name that inherits from the material theme in
res/values-v21/styles.xml
. - Set this theme as your app's theme in the manifest file.
Note: If your app uses the material theme but does not provide an alternative theme in this manner, your app will not run on versions of Android earlier than 5.0.
Provide Alternative Layouts
If the layouts that you design according to the material design guidelines do not use any of the new XML attributes introduced in Android 5.0 (API level 21), they will work on previous versions of Android. Otherwise, you can provide alternative layouts. You can also provide alternative layouts to customize how your app looks on earlier versions of Android.
Create your layout files for Android 5.0 (API level 21) inside res/layout-v21/
and your alternative layout files for earlier versions of Android inside res/layout/
. For example, res/layout/my_activity.xml
is an alternative layout for res/layout-v21/my_activity.xml
.
To avoid duplication of code, define your styles inside res/values/
, modify the styles in res/values-v21/
for the new APIs, and use style inheritance, defining base styles in res/values/
and inheriting from those in res/values-v21/
.
Use the Support Library
The v7 Support Libraries r21 and above includes the following material design features:
- Material design styles for some system widgets when you apply one of the
Theme.AppCompat
themes. - Color palette theme attributes in the
Theme.AppCompat
themes. - The
RecyclerView
widget to display data collections. - The
CardView
widget to create cards. - The
Palette
class to extract prominent colors from images.
System widgets
The Theme.AppCompat
themes provide material design styles for these widgets:
Color Palette
To obtain material design styles and customize the color palette with the Android v7 Support Library, apply one of the Theme.AppCompat
themes:
<!-- extend one of the Theme.AppCompat themes -->
<stylename="Theme.MyTheme"parent="Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_blue_500</item>
<item name="colorPrimaryDark">@color/material_blue_700</item>
<item name="colorAccent">@color/material_green_A200</item>
</style>
Lists and Cards
The RecyclerView
and CardView
widgets are available in earlier versions of Android through the Android v7 Support Library with these limitations:
CardView
falls back to a programmatic shadow implementation using additional padding.CardView
does not clip its children views that intersect with rounded corners.
Dependencies
To use these features in versions of Android earlier than 5.0 (API level 21), include the Android v7 Support Library in your project as a Gradle dependency:
dependencies {
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
}
Check the System Version
The following features are available only in Android 5.0 (API level 21) and above:
- Activity transitions
- Touch feedback
- Reveal animations
- Path-based animations
- Vector drawables
- Drawable tinting
To preserve compatibility with earlier versions of Android, check the system version
at runtime before you invoke the APIs for any of these features:
// Check if we're running on Android 5.0 or higher
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP){
// Call some material design APIs here
}else{
// Implement this feature without material design
}
Note: To specify which versions of Android your app supports, use the android:minSdkVersion
and android:targetSdkVersion
attributes in your manifest file. To use the material design features in Android 5.0, set the android:targetSdkVersion
attribute to 21
. For more information, see the <uses-sdk> API guide.
Material Design系列第七篇——Maintaining Compatibility的更多相关文章
- Material Design系列第三篇——Using the Material Theme
Using the Material Theme This lesson teaches you to Customize the Color Palette Customize the Status ...
- Material Design系列第八篇——Creating Lists and Cards
Creating Lists and Cards //创建列表和卡片 To create complex lists and cards with material design styles in ...
- Material Design系列第六篇——Defining Custom Animations
Defining Custom Animations //自定义动画 This lesson teaches you to //本节课知识点 Customize Touch Feedback //1. ...
- Material Design系列第五篇——Working with Drawables
Working with Drawables This lesson teaches you to Tint Drawable Resources Extract Prominent Colors f ...
- Material Design系列第四篇——Defining Shadows and Clipping Views
Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Custom ...
- Android Material Design系列之主题样式介绍说明
今天这篇文章应该算是Material Design系列的补充篇,因为这篇文章本来应该放到前面讲的,因为讲的是主题嘛,对于一些状态和颜色的介绍,因为我们一新建一个项目时,系统自带了三个属性的颜色,现在就 ...
- Material Design系列第二篇——Getting Started
Getting Started This lesson teaches you to Apply the Material Theme Design Your Layouts Specify Elev ...
- Material Design系列第一篇——Creating Apps with Material Design
Creating Apps with Material Design //创建Material Design的App Material design is a comprehensive guide ...
- Android Material Design 系列之 SnackBar详解
SnackBar是google Material Design提供的一种轻量级反馈组件.支持从布局的底部显示一个简洁的提示信息,支持手动滑动取消操作,同时在同一个时间内只能显示一个SnackBar. ...
随机推荐
- java做web项目比较多
WEB就是轻量级:如果要炫,FLEX或即将普及的html5.0都能做到像C/S那样. java做web项目比较多:如果是桌面程序,还是走C/S比较成熟. 如果是B/S架构的,后台还是JAVA,前台可以 ...
- windows下docker使用及注意事项
1.windows container模式下,pull镜像会失败 no matching manifest for windows/amd64 in the manifest list entries ...
- RNAcentral 数据库简介
RNAcentral 是EBI 开发的一个非编码RNA的数据库. 网址如下: http://rnacentral.org/ RNAcentral 整合了包括 Ensembl, GENCODE,Gree ...
- bioperl 自动化下载genbank 中的序列
当我们想要从genbank 中下载序列的时候,总需要点击右上角的download 按钮,选择对应的格式,然后通过浏览器进行下载,这样反复的点击很费时间了 其实可以通过bioperl 自动化的完成下载: ...
- Centos下查看cpu、磁盘、内存使用情况以及如何清理内存
核查服务器基本情况 查看内存使用情况 free -m 查看cpu使用情况 top #查看进程运行情况 查看磁盘以及分区情况 df -h 查看网络情况 ifconfig 查看端口使用情况 #1.方法一 ...
- Java多线程之细说线程池
前言 在认识线程池之前,我们需要使用线程就去创建一个线程,但是我们会发现有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因 ...
- java使用javax.mail进行免费的邮件发送
1. 建议发送方使用阿里云邮箱https://mail.aliyun.com/,阿里云默认是开启个人邮箱pop3.smtp协议的,所以无需在阿里云邮箱里设置,pop3.smtp的密码默认邮箱登录密码, ...
- Run ASP.NET MVC site on mac (mono/xamarin studio)
我们选择用xamarin studio来测试,如果你直接进xamarin的官网,那么会有一个更好看的网站和更复杂的流程(比如需要注册),我们直接到mono项目找mac的支持吧,点此进入 相关sdk和a ...
- 用好这6个APP,学英语SO EASY!
http://www.jianshu.com/p/30a27af18340
- iview给radio按钮组件加点击事件
<RadioGroup v-model="formValidate.phone"> <Radio label="phone">商家电话& ...