1. 目录名称
android的res目录是有规定的,分别是:
drawable
Bitmap files ( Bitmap files Nine-Patches (re-sizable bitmaps) State lists Shapes Animation drawables Other drawables layout XML files that define a user interface layout. values.png
, .9.png
, .jpg
, .gif
) or XML files that are compiled into the following drawable resource subtypes:
?
?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 Arbitrary files to save in their raw form. To open these resources with a raw XML files that define a state list of colors.Resources.getXML()
. Various XML configuration files must be saved here, such as a searchable configuration.
rawInputStream
, call Resources.openRawResource()
with the resource ID, which is R.raw.filename
.
color
?
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);
??
?
?