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.AppCompatthemes. - Color palette theme attributes in the
Theme.AppCompatthemes. - The
RecyclerViewwidget to display data collections. - The
CardViewwidget to create cards. - The
Paletteclass 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:
CardViewfalls back to a programmatic shadow implementation using additional padding.CardViewdoes 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. ...
随机推荐
- SpringMVC系列(十六)Spring MVC与Struts2的对比
• Spring MVC 的入口是 Servlet, 而 Struts2 是 Filter• Spring MVC 会稍微比 Struts2 快些. Spring MVC 是基于方法设计, 而 Stu ...
- 使用Maven构建项目
要构建一个基于Maven的项目,打开控制台,进入到 pom.xml 文件所放的项目文件夹,并发出以下命令: mvn package 这将执行Maven的“package”阶段. Maven构建生命周期 ...
- (转)Integrating Intel® Media SDK with FFmpeg for mux/demuxing and audio encode/decode usages 1
Download Article and Source Code Download Integrating Intel® Media SDK with FFmpeg for mux/demuxing ...
- 制作U盘启动安装CentOS Linux系统
制作U盘启动安装CentOS Linux系统 (特为老男孩教育&&51CTO学院在线三期同学而发) 方法一:使用UltraISO,将u盘做成启动盘 文件-->打开-->选择 ...
- Centos下查看cpu、磁盘、内存使用情况以及如何清理内存
核查服务器基本情况 查看内存使用情况 free -m 查看cpu使用情况 top #查看进程运行情况 查看磁盘以及分区情况 df -h 查看网络情况 ifconfig 查看端口使用情况 #1.方法一 ...
- .OFF 格式文件
转载:http://blog.sina.com.cn/s/blog_643634b80102v166.html 物体文件格式(.off)文件通过描述物体表面的多边形来表示一个模型的几何结构,这里的多边 ...
- 特殊权限set_uid /特殊权限set_gid/特殊权限stick_bit/软链接文件/硬连接文件
2.18 特殊权限set_uid 2.19 特殊权限set_gid 2.20 特殊权限stick_bit 2.21 软链接文件 2.22 硬连接文件 特殊权限set_uid(s权限用户user权限) ...
- Thinkphp5笔记一:项目部署
系统:window 7 64位 Thinkphp版本:5.0.5 环境:wampserver集成 笔记分为两大部分,配置篇与数据库篇 一.虚拟主机部署/本地部署 在网站根目录下建立文件index.ph ...
- DIV背景图片定位问题
<div class="custom-topNavigation_shadow"> </div> 正确写法 .custom-topNavigation_ ...
- 19 Go的全能ORM简单入门
gorm 昨天我的ldap账户改了以后,openfalcon(v2.1)-dashboard竟然无法登陆了!显然,没有把我的密码同步到本地数据库里面,怎么办?只能改openfalcon用户认证的源码了 ...