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


更多相关文章

  1. Android Studio & ADT 快捷键配置文件所在目录,自定义后可导入导
  2. 总目录
  3. Android UI系列 - 布局 - 目录
  4. android 目录结构,adb环境变量配置
  5. android 系统文件目录结构
  6. Android读取SD卡下面所有的TXT文件名 listView显示出来
  7. 遍历android根目录的简单资源查看器
  8. Android 读取 assets目录下的文件
  9. android 播放assets目录内的音乐,及使用Seekbar控制播放进度

随机推荐

  1. android:exported 属性详解
  2. Android应用开发入门五问
  3. Android常用控件总结
  4. android2.3 api demo 学习系列(1)--apidemo
  5. Win8/Android双系统 华硕Win8平板曝光
  6. Android(安卓)显示系统键盘搜索按键,实现
  7. Android(安卓)Broadcast receiver使用入
  8. Android(安卓)盘点所有Dialog 对话框 大
  9. Android系列教程之四:Android项目的目录结
  10. Android中几种图像特效处理的集锦