I have a android library project in which a ImageButton is used. The image file is located in src/assets/img. How to use imageButton.setImageUri() to set the image for this button? The library project will be exported as a jar file which will be used for other project. any idea?
code:
try
{
// get input stream
InputStream ims = mContext.getAssets().open("pause.png");
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, null);
// set image to ImageView
mPauseButton.setImageDrawable(d);
}
catch(IOException ex)
{
}
the above code is in the lib project. there is another project called ProjectA. projectA will pass its context to mContext for the lib project.