原文链接:http://my.oschina.net/u/874134/blog/158606
今天做一个Android的文件管理器,里面用到很多的地方用到了getResources。
- Drawable
currentIcon = null; - currentIcon
= getResources().getDrawable(R.drawable.folder); - currentIcon
= getResources().getDrawable(R.drawable.image);
- Resources
myResources = getResources(); - InputStream
myFile = myResources.openRawResource(R.raw.myfilename);
和传统的java文件操作一样,在android Api中提供了openFileInput和openFileOutput方法来读取设备上的文件。
简写
- InputStream
fs =this.getResources().openRawResource(R.raw.kb); (资源文件名为kb.html, 不需要带后缀.html) - InputStreamReader
read = new InputStreamReader (fs,”gb2312″); - BufferedReader
in = new BufferedReader(read);
读取res/drawable目录下的png或者bmg
- //得到Resources对象
- Resources
r = this.getContext().getResources(); - //以数据流的方式读取资源
- Inputstream
is = r.openRawResource(R.drawable.my_background_image); - BitmapDrawable
bmpDraw = new BitmapDrawable(is); - Bitmap
bmp = bmpDraw.getBitmap();