如何使用注释处理生成android资源(字符串,维度等)?

时间:2018-01-26 12:20:28

标签: java android annotation-processing

我想从注释中生成字符串资源。

@StringKey("style1")
void applyStyle1(){...}

编译项目后:

<resources>
 <!-- Automatically generated file. DO NOT MODIFY -->
 <!-- Values from product flavor: prod -->
 <string name="style1" translatable="false">style1</string>
</resources>

价值无关紧要

1 个答案:

答案 0 :(得分:2)

你想要实现这样的目标吗?

@ViewById
EditText myEditText;

@ViewById(R.id.myTextView)
TextView textView;

@StringRes(R.string.hello)
String helloFormat; //helloFormat will have the value of R.string.hello at runtime 

@ColorRes
int androidColor;

@BooleanRes
boolean someBoolean;

@SystemService
NotificationManager notificationManager;

@SystemService
WindowManager windowManager;

如果是,请查看https://github.com/androidannotations