Do an Android File manager today. It uses a lot of local uses getresources.
Drawable Currenticon = null;
..................
Currenticon = Getresources (). getdrawable (R.drawable.folder);
..................
Currenticon = Getresources (). getdrawable (R.drawable.image);
............
Drawable Currenticon = null;
..................
Currenticon = Getresources (). getdrawable (R.drawable.folder);
..................
Currenticon = Getresources (). getdrawable (R.drawable.image);
............
At first it was not very understanding why the C getresources () method would be able to acquire the resources that exist in the system. So I looked at the document and read the information:
For example: Put the resource file under the/raw/raw of the application. Then you can use Getresources in your app to get the resources. Open the file with the Openrawresource method (the name of the resource file without the suffix). Like what:
[Java] View plaincopyprint?
Resources myresources = Getresources ();
InputStream myFile = Myresources.openrawresource (r.raw.myfilename);
Resources myresources = Getresources ();
InputStream myFile = Myresources.openrawresource (r.raw.myfilename);
As with traditional Java file operations. The Openfileinput and Openfileoutput methods are available in the Android API to read the files on the device.
Shorthand
[Java] View plaincopyprint?
InputStream FS =this.getresources (). Openrawresource (R.RAW.KB); (The resource file name is called kb.html and does not require a suffix. html)
InputStreamReader read = new InputStreamReader (FS, "Gb2312″");
BufferedReader in = new BufferedReader (read);
InputStream FS =this.getresources (). Openrawresource (R.RAW.KB); (The resource file name is called kb.html and does not require a suffix. html)
InputStreamReader read = new InputStreamReader (FS, "Gb2312″");
BufferedReader in = new BufferedReader (read);
Read PNG or BMG under the Res/drawable folder
[Java] View plaincopyprint?
Get the Resources Object
Resources r = This.getcontext (). Getresources ();
Read a resource in a data flow way
InputStream is = R.openrawresource (r.drawable.my_background_image);
Bitmapdrawable Bmpdraw = new Bitmapdrawable (IS);
Bitmap bmp = Bmpdraw.getbitmap ();
Get the Resources Object
Resources r = This.getcontext (). Getresources ();
Read a resource in a data flow way
InputStream is = R.openrawresource (r.drawable.my_background_image);
Bitmapdrawable Bmpdraw = new Bitmapdrawable (IS);
Bitmap bmp = Bmpdraw.getbitmap ();
Or
[Java] View plaincopyprint?
InputStream is = Getresources (). Openrawresource (R.drawable.icon);
Bitmap Mbitmap = Bitmapfactory.decodestream (IS);
Paint Mpaint = new paint ();
Canvas.drawbitmap (Mbitmap, Max, mpaint);
InputStream is = Getresources (). Openrawresource (R.drawable.icon);
Bitmap Mbitmap = Bitmapfactory.decodestream (IS);
Paint Mpaint = new paint ();
Canvas.drawbitmap (Mbitmap, Max, mpaint);
Packet Package:android.content.res
Main categories: Resources
InputStream openrawresource (int id) gets the data stream for the resource. Reading resource Data
Put a picture resource, add your files to your project in the res/drawable/folder, from here. You will be able to reference it to your code or your XML layout, that is to say. Referencing it can also be used as a resource number, for example, if you choose a file only to remove the suffix (for example: My_image.png refers to it is my_image).
When you need to use XML resources. will be able to use Context.getresources (). getdrawable (R .... The address of the resource such as: R.string.ok);
When you do not have a legal context parameter, you can This.getcontext (). Getresources (); this makes.
Note that using getresource () when paying attention
1, must have a context Yes 2, it can be used as a member variable, the construction method parameters passed in or.
It.
Getresources () method