关闭

AndroidAnnotations——Injecting project Resources注入项目资源

标签: AndroidAnnotation
788人阅读 评论(0) 收藏 举报
分类:

Resources

Since AndroidAnnotations 1.0

All @XXXRes annotations indicate that an activity field should be injected with the correspondingAndroid resource from your res folder. The resource id can be set in the annotation parameter, ie@StringRes(R.string.hello).所有的 @XXXRes 注解标识一个activity字段应该由和res 文件夹下对应的Android resource 注入。这个资源id可以在注解参数中设置,@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.假如没有设置资源id,将默认使用字段名

@StringRes

The @StringRes annotation can be used to retrieve string resources. @StringRes 注解用来检索string资源。

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. @ColorRes 注解用来检索color资源。

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) orAnimationfields (much more interesting).@AnimationRes 注解可以注入 XmlResourceParser 字段(不常用)或者Animation字段(这种方式有趣的多)。

Usage example:用法:

@EActivity
public class MyActivity extends Activity {

  @AnimationRes(R.anim.fadein)
  XmlResourceParser xmlResAnim;
    
  @AnimationRes
  Animation fadein;

}

@DimensionRes

The @DimensionRes annotation can be used to retrieve dimension resources. @DimensionRes 注解用来检索dimension 资源。

Usage example:用法:

@EActivity
public class MyActivity extends Activity {

  @DimensionRes(R.dimen.fontsize)
  float fontSizeDimension;

  @DimensionRes
  float fontsize;

}

@DimensionPixelOffsetRes

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. @DimensionPixelOffsetRes 注解用来检索dimension 资源。获得一个以整型的像素偏移量为最终值的dimension 。这个注解功能和@DimensionRes一样,除了原始浮点数被截断成一个整型(像素)值。

Usage example:用法:

@EActivity
public class MyActivity extends Activity {

  @DimensionPixelOffsetRes(R.string.fontsize)
  int fontSizeDimension;

  @DimensionPixelOffsetRes
  int fontsize;

}

@DimensionPixelSizeRes

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. @DimensionPixelSizeRes注解用来检索dimension 资源。获得一个以整型的像素大小为最终值的dimension 。这个注解功能和@DimensionRes一样,除了原始浮点数被截断成一个整型(像素)值作为大小值。大小转换涉及到基值舍入,确保一个非零的基值至少有1像素的大小。

Usage example:用法:

@EActivity
public class MyActivity extends Activity {

  @DimensionPixelSizeRes(R.string.fontsize)
  int fontSizeDimension;

  @DimensionPixelSizeRes
  int fontsize;

}

Other @XXXRes

Here is the list of other supported resource annotations: 这里是其他支持资源注解的列表:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:65308次
    • 积分:1165
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:7篇
    • 译文:33篇
    • 评论:16条
    最新评论