AndroidAnnotations——Injecting project Resources注入项目资源
2013-12-04 20:11
471 查看
Resources
Since AndroidAnnotations 1.0All
@XXXResannotations indicate that an
activity field should be injected with the correspondingAndroid resource from your
resfolder.
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 @StringResannotation 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 @ColorResannotation 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
@AnimationRescan be used to inject
XmlResourceParserfields
(not very useful) or
Animationfields (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 @DimensionResannotation 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 @DimensionPixelOffsetResannotation
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 @DimensionPixelSizeResannotation 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
相关文章推荐
- AndroidAnnotations——Injecting project Resources注入项目资源
- AndroidAnnotations——Injecting SystemServices注入系统服务
- AndroidAnnotations——Injecting FragmentArg注入Fragment参数
- AndroidAnnotations——Injecting SystemServices注入系统服务
- AndroidAnnotations——Injecting html注入html文本
- AndroidAnnotations——Injecting html注入html文本
- Android 开源项目android-open-project工具库解析之(一) 依赖注入,图片缓存,网络相关,数据库orm工具包,Android公共库
- AndroidAnnotations——Injecting FragmentArg注入Fragment参数
- AndroidAnnotations——Injecting FragmentArg注入Fragment参数
- AndroidAnnotations 使用在library项目中出现无法找到R文件下资源索引的错误
- Android 开源项目android-open-project工具库解析之(一) 依赖注入,图片缓存,网络相关,数据库orm工具包,Android公共库
- [工具]android-unused-resources 找出项目中没用的资源
- Android Studio中项目资源出现: Validates resource references inside Android XML files
- 向Eclipse 中导入WorkSpace已有Android项目: Invalid project description->X overlaps the locaiton of another X
- 在Android项目中使用AndroidAnnotations(配置框架,显示Hello World!)
- android从资源文件,项目,sd卡获取图片
- 【Android游戏开发二十七】讲解游戏开发与项目下的hdpi 、mdpi与ldpi资源文件夹以及游戏高清版本的设置 推荐
- 【Android游戏开发二十七】讲解游戏开发与项目下的hdpi 、mdpi与ldpi资源文件夹以及游戏高清版本的设置
- svn检出项目eclipse无法识别成android project
- Maven项目右键->Maven->Update Project...后src/webapp/index.jsp、Java Resources有红叉提示