2017-12-14 14 views
0

탐색 서랍이있는 앱을 만들었습니다. 특정 네비게이션 메뉴 항목을 선택할 때 변경 될 작업 표시 줄 및 기본 아이콘의 색상을 변경하고 다른 항목을 선택할 때 기본값으로 변경해야합니다.상태 바에 따라 액션 바 색상과 아이콘이 변경됩니다.

내 코드

Fragment fragment; 
if(fragment.toString().contains("HomeFragment")){ 
      ab = ((BaseActivity)getApplicationContext()).getSupportActionBar(); 
      ab.setHomeButtonEnabled(true); 
      ab.setDisplayHomeAsUpEnabled(true); 
      ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF"))); 
      ab.setElevation(0); 
      ab.setDisplayHomeAsUpEnabled(true); 
      ab.setHomeAsUpIndicator(R.drawable.username); 
    } 
나는 위의 코드와 액션 바 색상 및 탐색 서랍 아이콘을 변경할 수 있지만, 다른 탐색 항목 선택에 기본 색상과 아이콘을 변경할 수 없습니다

.

+0

조각이 초기화되지 않습니다 코드를 계속합니다. 어쨌든 조각 findviewbyid 및 setonclicklistener onclick myviewitem.setbackground ... – Pomagranite

+0

은 완전한 코드가 아닙니다. 조각이 초기화되고 잘 동작합니다. "HomeFragment"를 선택하면 작업 표시 줄의 색이 바뀝니다. 하지만 탐색 탐색기 아이콘을 변경할 수 없습니다. – Visakh

답변

0

그냥

Fragment fragment; 
if(fragment.toString().contains("HomeFragment")){ 
      ab = ((BaseActivity)getApplicationContext()).getSupportActionBar(); 
      ab.setHomeButtonEnabled(true); 
      ab.setDisplayHomeAsUpEnabled(true); 
      ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF"))); 
      ab.setElevation(0); 
      ab.setDisplayHomeAsUpEnabled(true); 
      ab.setHomeAsUpIndicator(R.drawable.username); 
    } else { 
     ab = ((BaseActivity)getApplicationContext()).getSupportActionBar(); 
      ab.setHomeButtonEnabled(true); 
      ab.setDisplayHomeAsUpEnabled(true); 
      ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("your default color"))); 
      ab.setElevation(0); 
      //ab.setHomeAsUpIndicator(R.drawable.username); change it to your other icon; 
}