2 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以嘗試創(chuàng)建一個(gè)改變主題的 baseActivity,然后子類化該活動(dòng)并修改您的主題。讓我知道它是否有效

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
為了擴(kuò)展 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);
}
}
現(xiàn)在,從 ThemeChangeActivity 擴(kuò)展所有要更改主題的活動(dòng)。每當(dāng)您想更改活動(dòng)的主題時(shí),您都可以使用:
PreferenceManager
.getDefaultSharedPreferences(this)
.edit()
.putInt("ActivityTheme", R.id.theme_you_want_to_set)
.commit();
添加回答
舉報(bào)