You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Csaba Kozák edited this page Mar 16, 2016
·
8 revisions
Since AndroidAnnotations 1.0
All @XXXRes annotations indicate that an activity field should be injected with the corresponding Android resource from your res folder. The resource id can be set in the annotation parameter, ie @StringRes(R.string.hello).
If the resource id is not set, the name of the field will be used. The field must not be private.
@StringRes
The @StringRes annotation can be used to retrieve string resources.
The @DimensionPixelOffsetRes annotation can be used to retrieve dimension resources.
Retrieves the dimension to its final value as an integer pixel offset. This is the same as @DimensionRes, except the raw floating point value is truncated to an integer (pixel) value.
The @DimensionPixelSizeRes annotation can be used to retrieve dimension resources.
Retrieves the dimension to its final value as an integer pixel size. This is the same as @DimensionRes, except the raw floating point value is converted to an integer (pixel) value for use as a size. A size conversion involves rounding the base value, and ensuring that a non-zero base value is at least one pixel in size
Here is the list of other supported resource annotations:
@BooleanRes
@ColorStateListRes
@DrawableRes
@IntArrayRes
@IntegerRes
@LayoutRes
@MovieRes
@TextRes
@TextArrayRes
@StringArrayRes
Method based injection
Since AndroidAnnotations 4.0.0
This works for all of the previously mentioned @*Res annotations.
@EActivitypublicclassMyActivityextendsActivity {
@ColorRes(R.color.backgroundColor)
voidsetOneResource(intsomeColor){
// do something with someColor
}
voidsetMultipleBeans(@StringRes(R.string.hello) StringmyHelloString, @StringResStringhello){
// do something with myHelloString and hello
}
}