I have an android widget with a 9-patch background image.
Instead of using the main layout "android:background" property I use a RelativeLayout with an ImageView set behind other elements. The result is ok.
Now I want the user to be able to skin the widget, and especially choose the background color (using a color picker).
I'll find a way to build the new 9-patch at runtime but I firstly wanted to be sure that I was able to change the background 9-patch.
So I built manually a different 9-patch PNG and I compiled it using aapt.exe then put it on the phone. Then I tried to change the 9-patch using RemoteViews.setImageViewUri(). The result is that the new PNG is applied but not as a 9-patch, it is stretched instead.
Below the details:
The widget layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/widgetBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/rounded_black_70"/>
<LinearLayout
...
</LinearLayout>
</RelativeLayout>
Pictures describing the 9-patch files and the results: image
The line of code I use to set the new 9-patch:
remoteViews.setImageViewUri(R.id.widgetBackground, Uri.parse("/sdcard/DCIM/test.9.png"));
My question: has anyone of you ever managed to apply a new (generated at run time) 9-patch image using a remoteview?
What I have tried already:
I tried to apply the new image using a drawable and RemoteViews.setImageViewBitmap or setImageViewResource
I read the following post which says "I need to store it as a compiled nine patch. So that I can directly assign it to an ImageView (using its URI). As it's the only way to set a runtime generated nine patch on RemoteViews". It seems that this guy knew how to do it. Saving run-time generated NinePatch on external memory
so I learnt about compiled and not-compiled 9-patch.
I tried with files named ".9.png" or just ".png"
Thank you