Reputation: 25
I currently let the user choose a theme from the settings section, but when I try to apply the theme it doesn't work. The user has to exit the whole app and start over. I am new to android so I apologize if its a dumb question.
Upvotes: 0
Views: 122
Reputation: 348
Just go through the link below. It explains everything you need in detail.
http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html
Upvotes: 0
Reputation: 191
The way to do this would be to have a global variable in your MainActivity. This variable will store the preference selection that the user chooses.
public static String themeChoice;
Then in your onCreate method, you assign a value to this variable by query the prefrence manager.
themeChoice = PreferenceManager.getDefaultSharedPreferences(this).getString("themeChoice", "Default Theme");
Finally, in your onResume Method of the MainActivity, you can check to see if that variable equals the preference choosen by the user. And if it isn't it means that the theme changed and then you can recreate the activity.
if(!(themeChoice.equals(PreferenceManager.getDefaultSharedPreferences(this).getString("themeChoice", "Default Theme")))
recreate();
Upvotes: 2