Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use relativelayout.setBackgroundDrawable() with a bitmap?

I have a RelativeLayout object and want to dynamically change the background image with a dynamically created Bitmap object (it changes its color dynamically).

I saw that when I wanted to update the background image of the RelativeLayout object that I can only choose setBackgroundDrawable() which requires a Drawable object as a parameter.

My question is, how can I convert the dynamically created Bitmap object into a Drawable object?

like image 319
Dominik Avatar asked Sep 19 '11 05:09

Dominik


2 Answers

BitmapDrawable(obj) convert Bitmap object into drawable object.

Try:

RelativeLayout relative = (RelativeLayout) findViewById(R.id.relative1);
Drawable dr = new BitmapDrawable(bit);
(view).setBackgroundDrawable(drawable);

I hope this will help you.

like image 57
Siten Avatar answered Nov 07 '22 19:11

Siten


You can do it by this way

Drawable drawable = new BitmapDrawable(bitmap);
RelativeLayout r;
r = (RelativeLayout) findViewById(R.id.relativelayout1);
ll.setBackgroundDrawable(drawable);
like image 25
Nikunj Patel Avatar answered Nov 07 '22 19:11

Nikunj Patel