1

As of my previous question here I successfully managed to do this by transparent image. Now i want to change background color of images dynamically in remoteviews(PS I want to make widget like that and color of images in given link changes dynamically).

I tried following code:

ColorFilter cf = new PorterDuffColorFilter(-15032095, Mode.MULTIPLY);
        Drawable d= context.getResources().getDrawable(R.drawable.panel1);
        d.mutate();
        d.setColorFilter(cf);
        rv.setBitmap(R.id.rl_noti_main, "setColorFilter", drawableToBitmap(d));

but it didn't help. How can i achieve this? I have color codes in all formats integer, HEX or string whatever it will be needed. Please note that i want to do this only for given shapes in this link and for remoteview.

Thanks in Advance :)

Community
  • 1
  • 1
kiturk3
  • 549
  • 10
  • 30

2 Answers2

4

For someone else looking for it

remoteView.setInt(R.id.container, "setBackgroundColor", backgroundColor);
Brave Dolphin
  • 154
  • 1
  • 4
0

You cannot dynamically update widgets.

You can use the setBitmap() method to change the bitmap of a view inside a RemoteView. If the view is at the background, it should change the background. And then update the widget to make the changes to be applied.

If you are using RemoteViews in Notifications, you should update your notification after this. If you are using it in a Widget, you should use appWidgetManager.updateAppWidget(appWidgetId, views); function.

tasomaniac
  • 10,234
  • 6
  • 52
  • 84
  • Thanks tasomaniac.... I am using it in notifications. And seriously i didnt get you. can you explain in brief. I am using panel1 as drawable which resides in drawable folder and it is transparent.How to change color of that particular shape by code. i have tried rv.setInt(R.id.rl_main, "setBackgroundColor", -15032095) and many more. – kiturk3 Mar 17 '15 at 12:21
  • You can put an ImageView as a background and change its src using `setBitmap` or `setImageViewBitmap` functions. – tasomaniac Mar 17 '15 at 12:24
  • I will get color from color picker, so will it be possible? – kiturk3 Mar 17 '15 at 12:26
  • and also i have to type texts inside the view so will this also be possible? – kiturk3 Mar 17 '15 at 12:31
  • What do you mean type? With keyboard? Opening a keyboard is not possible. You can open an external Activity with an EditText inside with a keyboard. If you want to just change the text, there is also `setTextViewText` function inside RemoteViews. – tasomaniac Mar 17 '15 at 12:32
  • obviously i am talking about setTextViewText. I am setting received notification in one of the view. user will able to change the theme (color of view) according to his/her wish. I dont need to open keyboard for that. – kiturk3 Mar 17 '15 at 12:35