Android 5.0以下使用Material Design 特性
2014-11-20 14:22
316 查看
最近在学习Material Design的一些新特性,于是呢就用博客来记录一下自己的学习过程吧,正好也可以跟有缘人分享一下
Google提供了 v7 Support Libraries 让我们可以在 API level 21以下的设备上使用一些Material Design的特性。
但是遗憾的以下的这些特性还是只能在5.0+使用:
Activity transitions
Touch feedback
Reveal animations
Path-based animations
Vector drawables
Drawable tinting
是不是很坑爹…… 没办法啦
通过引用v7包,我们可以继承Theme.AppCompat主题来使用部分有Materail Design特性的控件:
并且使用v7包我们还可以通过继承Theme.AppCompat来定制Color Palette
首先我们可以定义可供选择的样式(styles文件)
1、在一个继承至老版本主题(像Holo主题)位于res/values/styles.xml的样式文件中定义正常的样式,而在res/values-v21/styles.xml中继承至Material Design Theme 的styls.xml中定义包含Material Design 特性的样式。
当然在有了styles.xml文件之后我们肯定要有可供选择的layout文件咯
2、在
Design的属性。这样就可以避免代码的重复~~~)
当然如果你要在Java代码中动态调用Material Design的API的话,就需要对当前的系统版本进行检测然后再调用
Google提供了 v7 Support Libraries 让我们可以在 API level 21以下的设备上使用一些Material Design的特性。
但是遗憾的以下的这些特性还是只能在5.0+使用:
Activity transitions
Touch feedback
Reveal animations
Path-based animations
Vector drawables
Drawable tinting
是不是很坑爹…… 没办法啦
通过引用v7包,我们可以继承Theme.AppCompat主题来使用部分有Materail Design特性的控件:
EditText
Spinner
CheckBox
RadioButton
SwitchCompat
CheckedTextView
并且使用v7包我们还可以通过继承Theme.AppCompat来定制Color Palette
<!-- extend one of the Theme.AppCompat themes --> <style name="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> 不但如此,我们还可以使用RecyclerView和CardView,怎么样 还是挺不错的吧。不过记得在引用这两个控件的时候要记得去添加依赖库哦~~ </span></span><pre name="code" class="html">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.+' } <span style="font-family:Roboto, sans-serif;">那么接下来问题来了?(此处省略15个字)</span>那如果你说如果我的Target版本就5.0+的呢?那是不是就要考虑向下兼容的问题了。
首先我们可以定义可供选择的样式(styles文件)
1、在一个继承至老版本主题(像Holo主题)位于res/values/styles.xml的样式文件中定义正常的样式,而在res/values-v21/styles.xml中继承至Material Design Theme 的styls.xml中定义包含Material Design 特性的样式。
当然在有了styles.xml文件之后我们肯定要有可供选择的layout文件咯
2、在
res/layout-v21/中定义你专门为Android5.0+提供的布局,而在
res/layout/中定义给5.0一下版本定义的布局。
(有个秘密要偷偷告诉你们O(∩_∩)O:在 res/values/中定义基本的样式,然后在/中继承至刚才定义的样式在添加上属于Materialres/values-v21
Design的属性。这样就可以避免代码的重复~~~)
当然如果你要在Java代码中动态调用Material Design的API的话,就需要对当前的系统版本进行检测然后再调用
相关文章推荐
- Android Material Design 详解(使用support v7兼容5.0以下系统)
- android 5.0新特性之Material Design 使用Material主题
- Android Material Design 详解(使用support v7兼容5.0以下系统(部分功能))
- Android Material Design 详解(使用support v7兼容5.0以下系统)
- Android Material Design 详解(使用support v7兼容5.0以下系统)
- Android(Lollipop/5.0) Material Design(五) 使用图片
- 解决Android使用Svg兼容5.0以下手机导致OOM的问题
- 使用android新特性:Material Design
- android5.X新特性--适配5.0以下的机型
- Android(Lollipop/5.0) Material Design(三) 使用Material主题
- android 5.0以下版本使用atof报错解决
- Android(Lollipop/5.0) Material Design(六) 使用图像
- RecyclerView(一)综合使用综述(Android 5.0 新特性)
- [置顶] Android(Lollipop/5.0) Material Design(六) 使用图片
- 运用layerlist在5.0以下的android上实现material design的阴影效果
- Android(Lollipop/5.0) Material Design(三) 使用Material主题
- Android进阶之路——Android Studio使用与5.0新特性
- Android 5.0以下,使用android studio 出现错误com.android.build.api.transform.TransformException:
- Material Design Android 5.0设计规范之CoordinatorLayout的使用
- Android 5.0新特性RecycleView的基本使用