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
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.
I think the solution looks like this:
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/label_bg" android:src="@drawable/widget_label_white"
android:scaleType="fitXY" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center"/>
<TextView android:gravity="center" android:id="@+id/label"
android:text="Processes" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:textColor="#ffffffff"
android:shadowColor="#ff000000" android:shadowDx="1"
android:shadowDy="1" android:shadowRadius="1" />
</FrameLayout>
This will make the background image fit the textview nicely.