android getResources的作用
2013-12-30 20:51
323 查看
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);
一开始不是很理解为什么用
getResources()这个方法就可以获取存在系统的资源。于是看了一下文档和翻阅了一下资料:
例如:把资源文件放到应用程序的/raw/raw下,那么就可以在应用中使用getResources获取资源后,以openRawResource方法(不带后缀的资源文件名)打开这个文件。例如:
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();
今天做一个Android的文件管理器,里面用到很多的地方用到了getResources。
Drawable currentIcon = null;
currentIcon = getResources().getDrawable(R.drawable.folder);
currentIcon = getResources().getDrawable(R.drawable.image);
一开始不是很理解为什么用
getResources()这个方法就可以获取存在系统的资源。于是看了一下文档和翻阅了一下资料:
例如:把资源文件放到应用程序的/raw/raw下,那么就可以在应用中使用getResources获取资源后,以openRawResource方法(不带后缀的资源文件名)打开这个文件。例如:
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();
相关文章推荐
- Android 中Parcelable的作用
- Android getResources的作用和需要注意点
- Android getResources的作用和需要注意点
- Android getResources的作用和需要注意点 .
- android getResources的作用
- Android getResources的作用和需要注意点
- Android getResources的作用和须要注意点
- Android 一张图理解getWidth…
- 发布 Android 应用-攻略
- Android activity跳转到另一个activity的指定fragment页面
- file的getPath getAbsolutePa…
- android 外部启动activity,…
- 【转】[Android] ImageView.S…
- android 上传图片至服务器
- 【ROM】[A500] Android …
- Android PopupWindow简单显示
- js乱码,php乱码,form get中文乱码
- Android Log.v(), Log.d…
- getElementsByClassName的用法 和 …
- Error: Target id 'android--1' is not valid. Use 'android.bat list targets' to get the target ids.