tags:

views:

279

answers:

1

Hello all, I have this really annoying problem:

In my widget, i would like to change the background by code. I noticed on the Google doc than I can easily change the background of an Imageview:

remoteViews.setImageViewResource(R.id.my_iv, R.drawable.my_bg);

Ok, too easy, i want to change now the Linear layout.. What I read about the remoteview id that I can change a Bitmap, Int, Bool, String, etc... but not a drawable. So i guess i cannot use:

remoteViews.setBitmap(R.id.my_ll,"setBackgroundDrawable",BitmapFactory.decodeResource(context.getResources(), R.drawablemy_bg));

I am totally disapointed and tried a last idea:

views.setInt(R.id.my_ll,"setBackgroundResource",R.drawable.my_bg);

But The logcat told me:

android.widget.RemoteViews$ActionException:view: android.widget.LinearLayout can't use method with RemoteViews: setBackgroundResource(int)

I am totally lost and I really don't know what to do...

I would really appreciate any help.

Thank a lot!

+1  A: 

You cannot modify the background that way, due to limitations in the RemoteViews API.

What you can do is choose a different layout -- one with the background you want -- when you create your RemoteViews instance for this particular update.

CommonsWare
yeah, I hadn't thought to this, that would have been a perfect solution.Unfortunately, i read you too late and meanwhile, I made something with a Framelayout and an imageview.I don't know if there are many differences or a really better way to do this to improve the perfs of the widget, but both seem to work.Thank for the answer.
Profete162