views:

27

answers:

1

i'm trying to define a theme for an appwidget, and have it applied at the application level. i have a theme like,

<style name="theme.dark"> 
  <item name="android"background">#000000</item> 
</style> 

in my manifest, i set android:theme="@style/theme.dark" at the application. however, when i run the appwidget, it does not pick up the items from the style. i tried setting style="@style/theme.dark" on an individual element in my view layout, and that does work ... but that's not what i want. i don't want to call out a specific style="..." for each element in my view. this page,

http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html

has an excellent example app for using themes / styles, and it works perfectly. the only difference is that it's an application .. and it's setting the theme on the activity, not the application.

i've also tried setting the theme at programmatically on the Context object using setTheme(...) in onHandleUpdate() of the appwidget, before the view is accessed. that doesn't work either.

any ideas? thanks.

A: 

Have you try

@Override 
protected void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  setTheme(R.style.Custom_Theme);
}

I'll refer you to DeveloperLife where i found that theme example i actually prefer loaded in the Manifest on my Activity

Necronet
as i mentioned, i'm using a widget. i don't have an onCreate() method. the first entry point into the widget is AppWidgetProvider.onUpdate(), and i've tried setting the theme there to no avail.
farble1670
i also tried creating a custom Application implementation and setting the theme in onCreate(...) there, which also had no effect.
farble1670
i wrote a sample app with an activity and a widget that use the same layout, and applied the theme at the application in the manifest. the theme is applied to the activity correctly, but not the widget. seems like there is a bug with widget. i filed issue 12100 on the AOSP.
farble1670