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();
添加回答
舉報
