Android的res目录

1. 目录名称

android的res目录是有规定的,分别是:

drawable

Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource subtypes:

Bitmap files

Nine-Patches (re-sizable bitmaps)

State lists

Shapes

Animation drawables

Other drawables

layout

XML files that define a user interface layout.

values

 

 XML files that contain simple values, such as strings, integers, and colors.

anim

XML files that define tween animations.

xml

Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML configuration files must be saved here, such as a searchable configuration.
raw

Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
color

XML files that define a state list of colors.

 

menu

XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.

如果不是以上目录会报"invalid resource directory name"的错误。

 

2. 目录下的文件名

在1中所述的res目录下的文件的文件名是有命名要求:must contain only [a-z0-9_.]

也就是说文件名只能包含小写字母、数字和下划线,

否则就会报错"invalid file name: must contain only [a-z0-9_.]"。

 

3. 目录资源的访问

res目录资源通过Resources的相应方法来访问。

相关的信息可以这样获取:

 

String packageName = context.getPackageName(); //包名 
Field[] fields = R.drawable.class.getDeclaredFields();
for (Field field : fields) { 
         String name = field.getName(); //资源文件名称 
} 
this.getResources().getIdentifier(name, "drawable", packageName); 

  

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值