2 回答
TA贡献1865条经验 获得超7个赞
为了扩展 Saham 的答案,这可以通过子类化 Activity 并覆盖 onCreate() 来解决:
public class ThemeChangeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
// Gets the saved theme ID from SharedPrefs,
// or uses default_theme if no theme ID has been saved
int theme = PreferenceManager.getDefaultSharedPreferences(this).getInt("ActivityTheme", R.id.default_theme);
// Set this Activity's theme to the saved theme
setTheme(theme);
// Continue with creation
super.onCreate(savedInstanceState);
}
}
现在,从 ThemeChangeActivity 扩展所有要更改主题的活动。每当您想更改活动的主题时,您都可以使用:
PreferenceManager
.getDefaultSharedPreferences(this)
.edit()
.putInt("ActivityTheme", R.id.theme_you_want_to_set)
.commit();
添加回答
举报