-
Notifications
You must be signed in to change notification settings - Fork 0
Resources
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.
The @StringRes annotation can be used to retrieve string resources.
Usage example:
@EActivity
public class MyActivity extends Activity {
@StringRes(R.string.hello)
String myHelloString;
@StringRes
String hello;
}The @ColorRes annotation can be used to retrieve color resources.
Usage example:
@EActivity
public class MyActivity extends Activity {
@ColorRes(R.color.backgroundColor)
int someColor;
@ColorRes
int backgroundColor;
}@AnimationRes can be used to inject XmlResourceParser fields (not very useful) or Animation fields (much more interesting).
Usage example:
@EActivity
public class MyActivity extends Activity {
@AnimationRes(R.anim.fadein)
XmlResourceParser xmlResAnim;
@AnimationRes
Animation fadein;
}The @DimensionRes annotation can be used to retrieve dimension resources.
Usage example:
@EActivity
public class MyActivity extends Activity {
@DimensionRes(R.dimen.fontsize)
float fontSizeDimension;
@DimensionRes
float fontsize;
}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.
Usage example:
@EActivity
public class MyActivity extends Activity {
@DimensionPixelOffsetRes(R.string.fontsize)
int fontSizeDimension;
@DimensionPixelOffsetRes
int fontsize;
}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
Usage example:
@EActivity
public class MyActivity extends Activity {
@DimensionPixelSizeRes(R.string.fontsize)
int fontSizeDimension;
@DimensionPixelSizeRes
int fontsize;
}Here is the list of other supported resource annotations:
@BooleanRes@ColorStateListRes@DrawableRes@IntArrayRes@IntegerRes@LayoutRes@MovieRes@TextRes@TextArrayRes@StringArrayRes
AndroidAnnotations was created by Pierre-Yves Ricau and is sponsored by eBusinessInformations.
27/12/2013 The 3.0 release is out !
- Get started!
- Download
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow