BrainCrash
BrainCrash

Reputation: 13172

Change remoteView ImageView background

I have some remoteView with ImageViews, and I need to change the "android:background" programmatically.

I know how to change the "android:src" with:

remoteView.setImageViewResource(int viewId, int srcId);

And it works fine, but how do I change the "android:background"?

Thanks

Upvotes: 22

Views: 20361

Answers (3)

Charleston
Charleston

Reputation: 1569

The jerry-rig way

I think you could do it using the jerry-rig way doing a second layout with the new background, then you create your remoteView using this new layout, like this:

  • RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget1);
  • RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget2);

after all, a layout isn't so expensive.

Upvotes: 0

jamapag
jamapag

Reputation: 9318

You can use public void setInt (int viewId, String methodName, int value) method.

remoteView.setInt(R.id.viewid, "setBackgroundResource", R.color.your_color)

Upvotes: 76

nicholas.hauschild
nicholas.hauschild

Reputation: 42849

Use setBackgroundResource(int).

Also, here is something you may take note of. When you look at Android documentation, if there is an xml element for a View that you can change, it normally points to the method to make the change at runtime.

Upvotes: 0

Related Questions