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);
更多相关文章
- Android Studio & ADT 快捷键配置文件所在目录,自定义后可导入导
- 总目录
- Android UI系列 - 布局 - 目录
- android 目录结构,adb环境变量配置
- android 系统文件目录结构
- Android读取SD卡下面所有的TXT文件名 listView显示出来
- 遍历android根目录的简单资源查看器
- Android 读取 assets目录下的文件
- android 播放assets目录内的音乐,及使用Seekbar控制播放进度