I have a view which has a method setBackgroundImage(BitmapDrawable) and I have an image imgbg in drawable folder in res.
How do I set this image as background image?
view.setBackgroundImage(R.drawable.imgbg); doesn’t work as R.drawable.imgbg is an integer but method requires drawable.
I know it’s silly thing but I’m not able sort it out even after intensive googling.
Any help appreciated.
Edit
This code snippet doesn’t belong to Activity class so I don’t have context object or getResources() or getApplicationContext()…
Edit 2 (Solution):
public class PieChartDemo01View extends View
{
public PieChartDemo01View(Context context)
{
super(context);
Drawable drawable = super.getResources().getDrawable(
R.drawable.bg2);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
}
}
Simple First get drawable then set cast in bitmapDrawable.
Just Do it Dear It`s work.