Last active
February 20, 2022 11:28
-
-
Save koinzhang/c8d6ffeb723b0ac669f215b63450e98d to your computer and use it in GitHub Desktop.
[DimenTool] 安卓Dimension生成工具 #Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenerateDimenTool { | |
public static void main(String[] args) { | |
StringBuilder sw400 = new StringBuilder(); | |
//添加xml开始的标签 | |
String xmlStart = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + | |
"<resources>\n"; | |
sw400.append(xmlStart); | |
//添加内容 | |
for (int i = 0; i <= 1920; i++) { | |
// 此处name后的标签名可以自定义"margin_"随意更改 | |
String start = "<dimen name=\"dimen_" + i + "\">"; | |
String end = "dp</dimen>"; | |
sw400.append(start).append(i).append(end).append("\n"); | |
} | |
//添加xml的尾标签 | |
sw400.append("</resources>"); | |
String sw400file = "./app/src/main/res/values/dimens.xml"; | |
writeFile(sw400file, sw400.toString()); | |
} | |
public static void writeFile(String file, String text) { | |
PrintWriter out = null; | |
try { | |
out = new PrintWriter(new BufferedWriter(new FileWriter(file))); | |
out.println(text); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment