Android 常用颜色资源文件color.xml

在网上找到一组常用颜色的资源文件,可惜,xml的注释写错了位置。xml的注释是要写在代码上方的,写在后方的注释并不正确。不像双斜杠//,更接近于/** */,文档注释,能够为变量生成doc的。


原color.xml:




#00000000
#FFFFFF
#FFFFF0
……
#8f8f8f



在eclipse中,注释部分将作为/** */注释加入到R.java文件中,。引用资源时,鼠标悬停,能够看到关于颜色的说明文字;注释放在xml代码的后方,将导致文档错乱为上一个的注释。如,R.color.white,鼠标悬停,说明文字将显示为“透明色”,而不是“白色”。Android Studio暂未发现提示自己写的xml注释。


因此,这么写是不对的。

于是,应该这么写:





#00000000

#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

#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

#D2B48C

#D2691E

#CD853F

#CD5C5C

#C71585

#C0C0C0

#BDB76B

#BC8F8F

#BA55D3

#B8860B

#B22222

#B0E0E6

#B0C4DE

#AFEEEE

#ADFF2F

#ADD8E6

#A9A9A9

#A52A2A

#A0522D

#9932CC

#98FB98

#9400D3

#9370DB

#90EE90

#8FBC8F

#8B4513

#8B008B

#8B0000

#8A2BE2

#87CEFA

#87CEEB

#808080

#808000

#800080

#800000

#7FFFD4

#7FFF00

#7CFC00

#7B68EE

#778899

#708090

#6B8E23

#6A5ACD

#696969

#66CDAA

#6495ED

#5F9EA0

#556B2F

#4B0082

#48D1CC

#483D8B

#4682B4

#4169E1

#40E0D0

#3CB371

#32CD32

#2F4F4F

#2E8B57

#228B22

#20B2AA

#1E90FF

#191970

#00FFFF

#00FFFF

#00FF7F

#00FF00

#00FA9A

#00CED1

#00BFFF

#008B8B

#008080

#008000

#006400

#0000FF

#0000CD

#00008B

#000080

#000000

#99cc33

#cccccc

#8f8f8f



这么长,其实我是通过编程完成位置的交换的。
代码如下:

读取文件,ReadServer.java:

package date0226pm.颜色表注释调整;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ReadServer {

	private ReadServer(){}
	public static ReadServer getServer(){
		return new ReadServer();
	}
	public String readFileToString(String path){
		File file = new File(path);
		StringBuilder sb = new StringBuilder();
		try {
			InputStream fis = new FileInputStream(file);
			InputStreamReader isr = new InputStreamReader(fis,"gbk");
			BufferedReader br = new BufferedReader(isr);
			char[] ch = new char[1024];
			int len = 0;
			
			while((len = br.read(ch))!=-1){
				sb.append(ch,0,len);
			}
			br.close();
			isr.close();
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}
}


正则表达式匹配颜色资源,交换位置,MoveServer.java:

package date0226pm.颜色表注释调整;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MoveServer {
	private MoveServer() {	}
	public static MoveServer getServer(){
		return new MoveServer();
	}
	public String moveString(String content){
		StringBuilder newStr = new StringBuilder();		
		String regex = "()()";
		
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(content);
		while (m.find()) {
			newStr.append(m.group(2)+"\n");
			newStr.append(m.group(1)+"\n");
		}
		
		return newStr.toString();
	}
}



将转换好的字符串,写入本地文件,WriteServer.java:

package date0226pm.颜色表注释调整;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class WriteServer {
	private WriteServer() {	}
	public static WriteServer getServer(){
		return new WriteServer();
	}
	public void writeStringToFile(String path,String content){
		File file = new File(path);
		
		if(file.exists()){
			System.out.println("文件已存在,写入副本");
			int lastDotIndex = path.lastIndexOf(".");
			String lastName = "";
			if (lastDotIndex == -1) {
				lastDotIndex = path.length();
			}else{
				lastName = path.substring(lastDotIndex+1, path.length());
			}
			path = path.substring(0, lastDotIndex)+"_副本."+lastName;			
			file = new File(path);
		}
		try {
			FileOutputStream fos = new FileOutputStream(file);
			OutputStreamWriter osw = new OutputStreamWriter(fos);
			BufferedWriter bw = new BufferedWriter(osw);
			bw.write(content);
			bw.flush();
			bw.close();
			osw.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
	
}



完成,并测试,Test.java:

package date0226pm.颜色表注释调整;

public class Test {

	public static void main(String[] args) {
		String path = "yanse.txt";
		String content = ReadServer.getServer().readFileToString(path);
		content = MoveServer.getServer().moveString(content);
		WriteServer.getServer().writeStringToFile(path, content);
		System.out.println("完毕...");
	}
}




——end






你可能感兴趣的:(Android)