Skip to content
pyricau edited this page Jan 14, 2012 · 4 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.

Usage example:

@EActivity
public class MyActivity extends Activity {

  @StringRes(R.string.hello)
  String myHelloString;

  @StringRes
  String hello;

}

@ColorRes

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

@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;

}

Other @XXXRes

Here is the list of other supported resource annotations:

  • @BooleanRes
  • @ColorStateListRes
  • @DimensionRes
  • @DimensionPixelOffsetRes
  • @DimensionPixelSizeRes
  • @DrawableRes
  • @IntArrayRes
  • @IntegerRes
  • @LayoutRes
  • @MovieRes
  • @TextRes
  • @TextArrayRes
  • @StringArrayRes

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally