Set Drawable background for a button on the RemoteView

526 Views Asked by At

I can set the background for a button on the remoteViews by using setInt method with Drawbale Id in the Drawable folder:

 remoteViews.setInt(R.id.btn_avatar, "setBackgroundResource", R.drawable.button_image);

I am trying to set the background for the button by:

  • Taking a photo by camera

  • Convert bitmap photo to Drawable and set it to the Button

    Drawable drawableIcon = new BitmapDrawable(this.context.getResources(), myBitmap);

The problem is that the drawableIcon object does not has R.drawable Id to use with setInt method. Can you please suggest me another method to set the drawableIcon object as button Background. Thank you so much!

2

There are 2 best solutions below

1
user3811067 On

RemoteView have api below

setImageViewBitmap(int viewId, Bitmap bitmap)

try this method. no need to convert Drawable.

0
Dinh Quang Tuan On

Finally, instead of using only one button, I use a button for the Drawable and an Imageview for the Bitmap and setViewVisibility to show only one View at once.