상태바 배경색상 변경시, 배경위에 표시되는 아이콘 및 텍스트 색도 배경에 맞게 조정이 필요함
상태바 색상 변경 클래스
public class StatusBarUtil {
public enum StatusBarColorType {
// 색 지정
WHITE_STATUS_BAR(R.color.color_white),
DEFAULT_STATUS_BAR(R.color.color_f9957f);
private int backgroundColorId;
StatusBarColorType(int backgroundColorId) {
this.backgroundColorId = backgroundColorId;
}
public int getBackgroundColorId() {
return backgroundColorId;
}
}
public static void setStatusBarColor(Activity activity, StatusBarColorType colorType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// 상태바 텍스트 색 지정
if(colorType.getBackgroundColorId() == R.color.color_f9957f) {
// 흰색
activity.getWindow().getDecorView().setSystemUiVisibility(0);
} else {
// 검은색
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
// 상태바 배경 색 지정
activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorType.getBackgroundColorId()));
}
}
}
onCreate내 호출
StatusBarUtil.setStatusBarColor(this, StatusBarUtil.StatusBarColorType.WHITE_STATUS_BAR);
'안드로이드' 카테고리의 다른 글
[Android] 안드로이드 Referrer 추출 (0) | 2020.08.14 |
---|---|
[Android] SNS 로그인 키해시(key hash) 추출 (0) | 2020.05.21 |
[Android] 인앱결제 예제 (BillingClient 사용) - 관리되는 제품 코드 (3) | 2020.04.14 |
[Android] 인앱결제 예제 (BillingClient 사용) - 판매자 계정 설정 , 아이템 등록 (0) | 2020.04.13 |
[Android] JSONObject["value"] not a string. 예외 (0) | 2020.04.08 |