public void setColor(@ColorInt @ColorRes int color){
// TODO
}
There is a problem with writing this way. For IDEs, this is ambiguous. If you want a Color value and a Color resource reference, will there be such an Int value? This type of annotation itself is only for IDE assistance. , that is, problems are discovered during compilation. You can disable this type of Lint by opening Inspections, as shown below:
Why not refer to the Android source code instead of defining a method that makes the caller crazy? The source code is as follows:
public void setBackgroundColor(@ColorInt int color) {
...
}
public void setBackgroundResource(@DrawableRes int resid) {
...
}
Multi-annotation code is as follows:
There is a problem with writing this way. For IDEs, this is ambiguous. If you want a Color value and a Color resource reference, will there be such an Int value?
This type of annotation itself is only for IDE assistance. , that is, problems are discovered during compilation. You can disable this type of Lint by opening
Inspections
, as shown below:Why not refer to the Android source code instead of defining a method that makes the caller crazy? The source code is as follows: