Possible Duplicate:
How to change current Theme at runtime in Android
I have an Android application where I allow users to switch between themes at runtime. Switching a theme is easy but the theme isn't applied until the activity is recreated. I found a way to apply the theme to current activity but if the user presses back button previous screens still have the old theme. How can I change theme for those activities? Example of app that supports it: Tasks Free
Settings. Under Display Options, tap Theme. Select the theme for this device: Light—White background with dark text.
You can create a theme the same way you create styles. The difference is how you apply it: instead of applying a style with the style attribute on a view, you apply a theme with the android:theme attribute on either the <application> tag or an <activity> tag in the AndroidManifest. xml file.
To change default themes go to File and click on Settings. A new Settings dialog will appear, like this. Under the Appearance & Behaviour -> Appearance, you will find Theme. Choose the right theme from the drop-down and click on Apply and then Ok.
Dynamically at runtime, call setTheme() in your activity's onCreate() method, before calling setContentView(). To change the theme, you simply need to restart your activity.
Please see this file..!
Also Want see this and this ... Hope this helps...!
Just a hint I suppose:
Before finish();
Call
setResult(AnIntegerThatNotifiesThePreviousActivitiesToChangeTheme);
Now in all your Activities, implement onActivityResult
protected void onActivityResult(int request, int result, Intent data) {
if(result == AnIntegerThatNotifiesThePreviousActivitiesToChangeTheme)
{
//update the current theme
}
}
Another solution (Better):
Implement a class that saves the theme:
public class CurrentThemeHolder {
private CurrentThemeHolder() {
}
private static instance;
public static getInstance() {
if(instance == null)
return new CurrentThemeHolder();
else
return instance;
}
private int mTheme; //identifier of the theme
public getTheme() {
return mTheme;
}
public setTheme(int newTheme){
mTheme = newTheme;
}
}
Now let all ur activities extend this ThemeActivity:
public class ThemeActivity extends Activity {
private int mTheme;
protected void onResume() {
if(mTheme != CurrentThemeHolder.getInstance().getTheme()) {
//do what you should do to set the theme
mTheme = CurrentThemeHolder.getInstance().getTheme();
//everytime you set the theme save it
//this maybe should be done in onCreate()
}
}
}
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