Android进阶之路——Android Studio使用与5.0新特性

http://blog.csdn.net/u012453500/article/details/49613671


Android Studio

特:一个工作空间只能有一个项目,其他的不能是项目只能是库

恢复窗体:

【View菜单】==>【Tool Windows】选项中可恢复ide下侧选项卡

【左下角屏幕类似小图标】可恢复左侧选项卡

1.软件初始配置

1.1 新建工作空间

注:由于新建过程过于雷同于eclipse新建项目,所以不在这里描述。工作空间内所有项目统一Android开发版本,在新建工作空间时会选择Android版本


1.2 新建项目

注意:可选择开发项目的适配设备或者是否是库文件。只后新建过程就是选择模板与创建项目名称,不再一一陈述


1.3 导入一个项目

注:如图可直接导入eclipse项目

1.4 设置如何自动编译工程


1.5 工程编码格式的修改


1.6 显示设置


1.7 自动导包

注:当导入被人的工程,如果勾选该项,则不用再去修复麻烦的包的问题

1.8 自动添加头描述


1.9 工程设置


1.10 快速打开项目的本地文件夹


1.11 应用签名创建、为应用签名、创建不签名的应用


注:未签名应用存放在【app\build\outputs\apk】路径下

2. AS要点

2.1 grandle文件的用处

(1)编译与运行Android虚拟机的版本配置,工程id、工程版本号与版本名都在其中配置

(2)作为项目的终极配置文件,无论是aidl、签名文件、资产目录等等都可以在这里面配置

[java]  view plain  copy
 print ?
  1. apply plugin: 'com.android.application'  
  2.   
  3. android {  
  4.     //编译运行版本配置  
  5.     compileSdkVersion 22  
  6.     buildToolsVersion "23.0.1"  
  7.   
  8.     //项目信息配置  
  9.     defaultConfig {  
  10.         applicationId "hello.doing.com.myapplication"  
  11.         minSdkVersion 21  
  12.         targetSdkVersion 23  
  13.         versionCode 1  
  14.         versionName "1.0"  
  15.     }  
  16.   
  17.     //编译类型  
  18.     buildTypes {  
  19.         release {  
  20.             minifyEnabled false //混淆,改成ture即为混淆项目  
  21.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //使用此txt指定混淆文件混淆工程  
  22.         }  
  23.     }  
  24. }  
  25.   
  26. dependencies {  
  27.     //把libs下所有jar包导入进工程  
  28.     compile fileTree(include: ['*.jar'], dir: 'libs')  
  29.     compile 'com.android.support:support-v4:23.0.1'  
  30. }  

2.2 快捷键

(1)自动修复:Alt  + Enter

(2) 提示:Ctrl  +  P

(3)自动内容提示并填写:Ctrl  +  Alt  +  空格

(4)删除当前行:Ctrl  +  Y

(5)复制当前行:Ctrl  + D

(6)移动当前行: Alt  +  Shift  +   上下方向键

(7)优化导包:Ctrl  +  Alt  + O

(8)获取get、set、父类方法、构造方法:Alt  +  Insert

(9)格式化代码:Ctrl  +  Alt  +  L

(10)打开最近更改的文件:Ctrl  +  E

(11)替换文本:Ctrl  +  R

(12)注释:Ctrl  +  /         多行注释:Ctrl  +  Shift  +  / (选中目标)

(13)显示当前类的继承结构:Ctrl  +  H

(14)显示注释文档:Ctrl  +  Q(选中目标)

(15)查看源码快捷键:Ctrl  +  Alt  + 左右方向键

(16)可以把选定代码放到try catch、选择、判断、循环语句中:Ctrl  +  Alt  +  T

(17)快速查找当前类中某一方法:Ctrl  +  F12

(18)为当前行做一个Android Studio独有标记:Ctrl  +  F11

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 上下层都显示。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值