0
나는 앱을 가지고 있으며 사용자가 설정에서 색상을 선택할 때 앱의 ColorPrimary를 변경하고 싶습니까? 내가 어떻게 할 수 있니?환경 설정을 변경 한 경우 ColorPrimary를 변경하는 방법은 무엇입니까?
나는 앱을 가지고 있으며 사용자가 설정에서 색상을 선택할 때 앱의 ColorPrimary를 변경하고 싶습니까? 내가 어떻게 할 수 있니?환경 설정을 변경 한 경우 ColorPrimary를 변경하는 방법은 무엇입니까?
색이 호출이 방법
void onBackgroundColor(String color){
switch(color){
case "red":
sSavePreferences(getApplicationContext(), "color", "blue");
setBackground(color);
break;
case "blue":
sSavePreferences(getApplicationContext(), "color", "blue");
setBackground(color);
break;
case "green":
sSavePreferences(getApplicationContext(), "color", "blue");
setBackground(color);
break;
default:break;
}
}
void setBackground(String color){
//code to change background color
}
설정에서 선택이 된 SharedPreferences
public static void sSavePreferences(Context context, String key, String value) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
그리고 활동의 한 OnCreate를 사용하여 설정을 저장하는 방법입니다 때 당신은 사용하여 이전 색상을로드 할 수 있습니다 이 방법
setBackground(sLoadSavedPreferencesString(getApplicationContext(), "color"));
로드 중 색상 :
하지만 배경색을 변경하는 대신 ColorPrimary를 변경하려면 어떻게해야합니까? –
설정을 SharedPreferences에 저장해야합니다. 표시보기 인 경우 SharedPreferences에서 값을로드해야합니다. 사용자가 색상을 선택하면 [LocalBroadcastManager] (http://stackoverflow.com/questions/8802157/how-to-use-localbroadcastmanager) 또는 [EventBus] (https : //)를 사용하여 값이 변경되었음을 앱에 알릴 수 있습니다. github.com/greenrobot/EventBus) – maphongba008
@ maphongba008 ok,하지만 색상을 변경하는 방법은 무엇입니까? –
여전히 문제를 해결할 수 없다면 예제 코드 – maphongba008