How to change the background of a widget using RemoteView?

<RelativeLayout android:id="@+id/widget" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/my_background" android:orientation="vertical" > 

And now I want to change this background to "@ drawable / your_bck" using RemoteView. I tried something like this

 Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.yout_bck); remoteViews.setImageViewBitmap(R.id.widget, bitmap); , R.drawable.yout_bck); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.yout_bck); remoteViews.setImageViewBitmap(R.id.widget, bitmap); 

But then it shows that “Widget is not loading”

It should be as the background, because I needed to set the text in the center of the picture :)

+4
source share
1 answer

You call setImageViewBitmap on RelativeLayout . A RelativeLayout is not ImageView . Instead, you can put out there ImageView , which fills RelativeLayout and causes it.

+3
source

Source: https://habr.com/ru/post/1391962/


All Articles