Android语法清单

Gradle

  1. Lambda表达式导包表达式
android {
        ...
    defaultConfig {
        jackOptions.enabled = true
        ...
    }
    compileOptions{
        sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
        targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
    }
}

注:AS2.1以上时,app的build.gradle里不要加
apply plugin: 'me.tatarka.retrolambda'

针对错误
Cannot get property 'destinationDir' on null object

JAVA

1. 字符串资源里变量替换

关键标记号

%字符序号$s

比如,

第%1$s页

程序中

String page = getString(R.string.page,"666");  

多个变量的

//资源文件
第%1$s页%2$s行

//代码
String page = getString(R.string.page,"345","24");

2. JAVA文件中字体加粗
//Typeface
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
//TextPaint
textView.getPaint().setFakeBoldText(true); 

资源文件

1. colors.xml 颜色值大全
 
 
#FFFFFF 
#FFFFF0 
#FFFFE0 
#FFFF00 
#FFFAFA 
#FFFAF0 
#FFFACD 
#FFF8DC 
#FFF5EE 
#FFF0F5 
#FFEFD5 
#FFEBCD 
#FFE4E1 
#FFE4C4 
#FFE4B5 
#FFDEAD 
#FFDAB9 
#FFD700 
#FFC0CB 
#FFB6C1 
#FFA500 
#FFA07A 
#FF8C00 
#FF7F50 
#FF69B4 
#FF6347 
#FF4500 
#FF1493 
#FF00FF 
#FF00FF 
#FF0000 
#FDF5E6 
#FAFAD2 
#FAF0E6 
#FAEBD7 
#FA8072 
#F8F8FF 
#F5FFFA 
#F5F5F5 
#F5F5DC 
#F5DEB3 
#F4A460 
#F0FFFF 
#F0FFF0 
#F0F8FF 
#F0E68C 
#F08080 
#EEE8AA 
#EE82EE 
#E9967A 
#E6E6FA 
#E0FFFF 
#DEB887 
#DDA0DD 
#DCDCDC 
#DC143C 
#DB7093 
#DAA520 
#DA70D6 
#D8BFD8 
#D3D3D3 
#D3D3D3 
#D2B48C 
#D2691E 
#CD853F 
#CD5C5C 
#C71585 
#C0C0C0 
#BDB76B 
#BC8F8F 
#BA55D3 
#B8860B 
#B22222 
#B0E0E6 
#B0C4DE 
#AFEEEE 
#ADFF2F 
#ADD8E6 
#A9A9A9 
#A9A9A9 
#A52A2A 
#A0522D 
#9932CC 
#98FB98 
#9400D3 
#9370DB 
#90EE90 
#8FBC8F 
#8B4513 
#8B008B 
#8B0000 
#8A2BE2 
#87CEFA 
#87CEEB 
#808080 
#808080 
#808000 
#800080 
#800000 
#7FFFD4 
#7FFF00 
#7CFC00 
#7B68EE 
#778899 
#778899 
#708090 
#708090 
#6B8E23 
#6A5ACD 
#696969 
#696969 
#66CDAA 
#6495ED 
#5F9EA0 
#556B2F 
#4B0082 
#48D1CC 
#483D8B 
#4682B4 
#4169E1 
#40E0D0 
#3CB371 
#32CD32 
#2F4F4F 
#2F4F4F 
#2E8B57 
#228B22 
#20B2AA 
#1E90FF 
#191970 
#00FFFF 
#00FFFF 
#00FF7F 
#00FF00 
#00FA9A 
#00CED1 
#00BFFF 
#008B8B 
#008080 
#008000 
#006400 
#0000FF 
#0000CD 
#00008B 
#000080 
#000000 

使用

colorRes blueRes = getResources().getColor(R.drawable.blue);
tv是textView
//tv.setTextColor(this.getResources().getColor(R.color.green));//已经过时
tv.setTextColor(ContextCompat.getColor(this,R.color.green));//替代已过时getColor

你可能感兴趣的:(Android语法清单)