There is no setBackground()
method in the RemoteViews
class, so I've used the following workaround:
FrameLayout
for my app widget with an ImageView
as the background view.ImageView
image using setImageViewResource()
method.Unfortunately, when it comes to 9-patch drawables this method does not work. Also when an ImageView
's android:src
attribute points to 9-patch - it doesn't work too. Is there any way to change the AppWidget
's background image programatically using a 9-patch drawable? Thanks in advance.
EDIT Settings the 9-patch as initial background in the XML:
<ImageView
android:id="@+id/small_widget_layout_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_lime" />
When I use android:src="@drawable/background_lime"
it doesn't stretch the image properly, this code works fine. And the code to change the background from the AppWidgetProvider
onUpdate
method:
views.setImageViewResource(R.id.small_widget_layout_bg,
R.drawable.backgroung_lime);
This does not stretch the image as a 9-patch.
This answer was diagnosed in the above comments...
RemoteView
doesn't allow access to View.setBackground()
, so your workaround of using the android:src
property of an ImageView
is good, providing that the android:scaleType
property is set to fitXY.
ImageView
won't stretch it's foreground image unless you tell it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With