Android 5.0新特性

Android 5.0新特性

1.Material Design设计语言

注意:必须用在API 21以上版本

1.1 主题

谷歌官方我们提供了三种配色风格的Material Design样式:

  1. 黑色主题 Theme.Material
  2. 明亮主题 Theme.Material.Light
  3. 明亮主题黑色ActionBar Theme.Material.Light.DarkActionBar

注:这是在values-21目录下的style.xml中定义的主题样式,只适用于API 21或更高版本

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <style name="AppTheme" parent="android:Theme.Material.Light">  
  4.         <!-- 状态栏颜色,会被statusBarColor效果覆盖 -->  
  5.         <item name="android:colorPrimaryDark">#66ccff</item>  
  6.         <!-- 状态栏颜色,继承自colorPrimaryDary -->  
  7.         <item name="android:statusBarColor">#720ecc</item>  
  8.         <!-- actionBar颜色 -->  
  9.         <item name="android:colorPrimary">#cc311f</item>  
  10.         <!-- 底部栏颜色 -->  
  11.         <item name="android:navigationBarColor">#34cc44</item>  
  12.         <!-- 字体颜色 -->  
  13.         <item name="android:textColor">#cc3239</item>  
  14.     </style>  
  15. </resources>  



主题颜色常用代码:

  1. android:colorPrimaryDark 应用的主要暗色调,statusBarColor默认使用该颜色
  2. android:statusBarColor 状态栏颜色,默认使用colorPrimaryDark
  3. android:colorPrimary 应用的主要色调,actionBar默认使用该颜色
  4. android:windowBackground 窗口背景颜色
  5. android:navigationBarColor 底部栏颜色
  6. android:colorForeground 应用的前景色,ListView的分割线,switch滑动区默认使用该颜色
  7. android:colorBackground 应用的背景色,popMenu的背景默认使用该颜色
  8. android:colorAccent 一般控件的选种效果默认采用该颜色
  9. android:colorControlNormal 控件的默认色调 
  10. android:colorControlHighlight 控件按压时的色调
  11. android:colorControlActivated 控件选中时的颜色,默认使用colorAccent
  12. android:colorButtonNormal 默认按钮的背景颜色
  13. android:textColor Button,textView的文字颜色
  14. android:textColorPrimaryDisableOnly RadioButton checkbox等控件的文字
  15. android:textColorPrimary 应用的主要文字颜色,actionBar的标题文字默认使用该颜色

1.2 阴影

注:5.0中添加的坐标Z轴,可以设置控件距离屏幕的距离,由此产生了阴影

特殊:产生阴影的控件的父控件必须范围大于子控件,否则子控件将被截取,无法显示阴影

[html]  view plain  copy
 print ?
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.                 android:layout_width="match_parent"  
  3.                 android:layout_height="match_parent"  
  4.     >  
  5.   
  6.     <!-- 背景是纯色或者shape图形可添加Z轴阴影,如果背景是图片,不能直接设置背景,需要用代码来控制设置-->  
  7.     <TextView  
  8.         android:id="@+id/tv_head"  
  9.         android:layout_width="200dp"  
  10.         android:layout_height="200dp"  
  11.         android:layout_marginLeft="100dp"  
  12.         android:layout_marginTop="100dp"  
  13.         android:background="#fff"  
  14.         android:elevation="50dp"  
  15.         android:text="@string/hello_world"  
  16.         android:textSize="30sp"/>  
  17.   
  18.     <TextView  
  19.         android:layout_width="200dp"  
  20.         android:layout_height="200dp"  
  21.         android:layout_marginLeft="200dp"  
  22.         android:layout_marginTop="200dp"  
  23.         android:background="#fff"  
  24.         android:elevation="49dp"  
  25.         android:text="@string/hello_world"  
  26.         android:textSize="30sp"/>  
  27.   
  28.   
  29. </RelativeLayout>  

效果演示:


特殊请注意:如果控件背景是一张图片则不能指通过布局来设置阴影,阴影将无法显示。要通过代码来控制

[java]  view plain  copy
 print ?
  1. TextView tv_head = (TextView) findViewById(R.id.tv_head);  
  2. ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {  
  3.     public void getOutline(View view, Outline outline) {  
  4.         // 可以指定圆形,矩形,圆角矩形,path  
  5.         outline.setOval(00, view.getWidth(), view.getHeight());  
  6.     }  
  7. };  
  8. tv_head.setOutlineProvider(viewOutlineProvider);  

1.3 裁剪

注:方便的裁减控件
[java]  view plain  copy
 print ?
  1. TextView tv_head = (TextView) findViewById(R.id.tv_head);  
  2. ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {  
  3.     public void getOutline(View view, Outline outline) {  
  4.         // 指定控件裁减为圆角矩形  
  5.         outline.setRoundRect(0,0,view.getHeight(),view.getWidth(),30);  
  6.         // 指定控件裁减为圆形  
  7.         outline.setOval(00, view.getWidth(), view.getHeight());  
  8.     }  
  9. };  
  10. tv_head.setOutlineProvider(viewOutlineProvider);  
  11. tv_head.setClipToOutline(true);//裁减要设置的方法  

1.4 选择器——单张图片

使用方法:在【drawable】目录下创建一个bitmap的xml文件代替按下时的图片,然后选择器按下时的图片选择此bitmap的xml文件即可。bitmap写法如下:

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <bitmap  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:src="@mipmap/selector"  
  5.     android:tint="#66ccff"  
  6.     android:tintMode="multiply"/>  
  7. <!-- tint属性是图片被按下时变化的颜色   tintMode是颜色的显示样式-->  

tint的渲染模式有总共有16种,xml文件中可以使用6种,代码中我们可以设置16种,渲染模式决定了渲染颜色和原图颜色的取舍和合成规则:


  1. PorterDuff.Mode.CLEAR 所绘制不会提交到画布上。
  2. PorterDuff.Mode.SRC 显示上层绘制图片
  3. PorterDuff.Mode.DST 显示下层绘制图片
  4. PorterDuff.Mode.SRC_OVER 正常绘制显示,上下层绘制叠盖。
  5. PorterDuff.Mode.DST_OVER 上下层都显示。下层居上显示。
  6. PorterDuff.Mode.SRC_IN 取两层绘制交集。显示上层。
  7. PorterDuff.Mode.DST_IN 取两层绘制交集。显示下层。
  8. PorterDuff.Mode.SRC_OUT 取上层绘制非交集部分。
  9. PorterDuff.Mode.DST_OUT 取下层绘制非交集部分。
  10. PorterDuff.Mode.SRC_ATOP 取下层非交集部分与上层交集部分
  11. PorterDuff.Mode.DST_ATOP 取上层非交集部分与下层交集部分
  12. PorterDuff.Mode.XOR 取两层绘制非交集。两层绘制非交集。
  13. PorterDuff.Mode.DARKEN 上下层都显示。变暗
  14. PorterDuff.Mode.LIGHTEN 上下层都显示。变亮
  15. PorterDuff.Mode.MULTIPLY 取两层绘制交集
  16. PorterDuff.Mode.SCREEN 上下层都显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值