-3

안녕하세요 공유 환경 설정을 사용하여 APP 색상을 저장하고 있습니다. 지금까지 드로어 블 색을 사용하지 않았기 때문에 단추와 상태 표시 줄의 색을 저장할 수 있습니다.공유 환경 설정 드로이드 컬러 Android

이것은 내 기능은 다음과 같습니다

private void storeColor(int color){ 
    SharedPreferences mSharedpreferences = getSharedPreferences("ToolbarColor", MODE_PRIVATE); 
    SharedPreferences.Editor mEditor = mSharedpreferences.edit(); 
    mEditor.putInt("color", color); 
    mEditor.apply(); 
} 

private int getColor(){ 
    SharedPreferences mSharedPreferences = getSharedPreferences("ToolbarColor", MODE_PRIVATE); 
    int selectedColor = mSharedPreferences.getInt("color", getResources().getColor(R.color.colorPrimary)); 

    return selectedColor; 
} 

그리고 나는이처럼 사용하고 있습니다

if (intValue == 1){ 
      getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.green_apple)); 
      btn_historial.setBackgroundColor(getResources().getColor(R.color.green_apple)); 
      if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       getWindow().setStatusBarColor(getResources().getColor(R.color.green_apple)); 
      } 
      storeColor(getResources().getColor(R.color.green_apple)); 
     } 


if(getColor() != getResources().getColor(R.color.colorPrimary)){ 
      getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorPrimary)); 
      btn_historial.setBackgroundColor(getColor()); 
      if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       getWindow().setStatusBarColor(getColor()); 
      } 
     } 

내가하지만, 도구 모음을 사용되기 전에이 지금은 작업 표시 줄을 사용하고 싶습니다. 약간의 손실이 있습니다 여기에 드로어 블 색상을 어떻게 추가 할 수 있습니까?

+0

공유 환경 설정에서 색상을 추가 하시겠습니까? –

+0

음, sharepreferences에서 작업 표시 줄에 배경색을 추가 하시겠습니까? 그리고 sharepreference에 drawable을 저장하는 방법을 확신하지 못합니까? – jmarkstar

+0

@ArpitPatel 예 – cotita

답변

0

ColorDrawable을 사용하십시오.

int color = getColor(); 
getActionBar().setBackgroundDrawable(new ColorDrawable(color)); 
+0

더 좋을 수도 있습니다. 'Color.parseColor (color);' – marlonpya

+0

@marlonpya 정수 색상이라고 생각합니다. 'Color.parseColor (color);는 string을위한 것이다. – Hiking

+0

완벽하게 작동합니다. 나는 지나치지 않았다. 고맙습니다 !!! – cotita