只是一個提示,我想:
之前finish();
呼叫
setResult(AnIntegerThatNotifiesThePreviousActivitiesToChangeTheme);
現在,在所有的活動,實現onActivityResult
protected void onActivityResult(int request, int result, Intent data) {
if(result == AnIntegerThatNotifiesThePreviousActivitiesToChangeTheme)
{
//update the current 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;
}
}
現在,讓你的生命活動擴展這個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()
}
}
}
你好警長,我想從您知道是否有可能是任何解決方案,我從網上得到的顏色代碼,並根據我可以改變我的所有按鈕運行時的顏色而不去所有的特定按鍵和應用背景顏色,莫不是任何解決方案使用主題或風格?請分享您的任何建議。 – MKJParekh 2014-03-20 07:54:23
你有無限的色彩嗎?或只是有限的一套顏色? – 2014-03-21 15:15:30
我做有限的20種顏色的發言權,但那些20會從服務器上下載的,因此可能會有所不同,從一個時間到另一個,總之顏色是15-20左右(不是修復),以及那些顏色代碼也沒有解決。其中一個用戶已經建議使用CustomViews http://stackoverflow.com/questions/22529646/android-app-apply-color-theme-dynamically-at-runtime – MKJParekh 2014-03-22 04:40:24