Forecast widget : change layout background image dynamically

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Forecast widget : change layout background image dynamically

Postby Koxx » Sun Jun 14, 2009 8:14 pm

Hello,

I'd like to change my widget background image dynamically, is it possible ?

I want to use a external image instead of a res/drawable.

:P
Koxx
Freshman
Freshman
 
Posts: 6
Joined: Sat Jun 13, 2009 3:08 pm
Location: PARIS

Top

Postby WarrenFaith » Fri Jun 19, 2009 9:07 am

down!

Yes it is possible to change the background of your widget dynamically.

Getting a external image you have to use the internet. Check the reference for URLRequest and don't forget to set the INTERNET permission in your Manifest.

And a warning from me as Moderator:
We dont like simple "up!" posts. If nobody answer you try to be more specific. Post what you have so far and on which point you stuck.
I deleted your "up"-posts....
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby Koxx » Sat Jul 04, 2009 12:33 pm

Thanks for this answer... and sorry for my mistake.

How can I do to change it, here is my question. Forget about "external image". Even if I use a internal drawable ressource, it's OK.

I tried theme & style, it doesn't works. It doesn't show any background image.

I tried RemoteViews.setImageViewResource on an ImageView filling the widget, but i doesn't strech my 9patch image correctly (and it doesn't seems to change background, it add another image).

Can you explain please ?


My test with Themes :

-------------------------
layout.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
style="?attr/widgetBackground"
>

....

-------------------------
attrbs.xml

<resources>
<attr name="widgetBackground" format="reference" />
</resources>

-------------------------
styles.xml


<resources>

<style name="ThemeKxDark" parent="@android:style/Theme">
<item name="widgetBackground">@style/blackBackground</item>
</style>

<style name="ThemeKxLight" parent="@android:style/Theme">
<item name="widgetBackground">@style/whiteBackground</item>
</style>


<style name="whiteBackground">
<item name="android:background">@drawable/widget_bg_normal_white</item>
</style>

...

-------------------------
widget code

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

// context.setTheme(R.style.ThemeKxLight);

// If no specific widgets requested, collect list of all
if (appWidgetIds == null) {
appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, LargeAppWidget.class));
}

context.setTheme(R.style.ThemeKxLight);

// Request update for these widgets and launch updater service
UpdateService.requestUpdate(appWidgetIds);
context.startService(new Intent(context, UpdateService.class));
}

...
Koxx
Freshman
Freshman
 
Posts: 6
Joined: Sat Jun 13, 2009 3:08 pm
Location: PARIS

Postby pcm2a » Wed Dec 09, 2009 9:52 pm

I'd like to know how to do this too. In my case I need to turn the background image on or off from the widget code.
pcm2a
Developer
Developer
 
Posts: 27
Joined: Tue Aug 11, 2009 4:54 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests