[안드로이드 / Kotlin] windowLightStatusBar

2021. 9. 1. 18:11·Android
반응형

안드로이드에서 다크모드, 라이트모드 혹은 임의 지정한 Status Bar 색상에 따라 상태바 내의 글씨가

보이지 않는 경우가 있습니다. 이 문제를 해결하기 위한 방법을 알아보도록 하겠습니다.

 

<xml 코드>

<item name="android:windowLightStatusBar">true</item>

위 코드를 res/values/theme.xml 에 추가하면 됩니다.

(단, 해당 코드는 안드로이드 API 23 이상 부터 사용할 수 있으며,

windowLightStatusBar 값이 true는 라이트모드, false일 경우 다크모드 시에 사용합니다 )

 

<소스 코드>

// API 30부터 deprecated됨 (API 30 이전)
// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE

// 대체 코드 (API 30 이후)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = true

기존에는 window.decorView.systemUiVisibility()를 이용해서 해결할 수 있었지만, 해당 메소드는 안드로이드 API 30 부터 

deprecated 되었습니다.

API 30이상 부터는 WindowInsetsControllerCompat을 이용하면 해결할 수 있습니다.

 

 

<참고자료>

https://stackoverflow.com/questions/42789789/set-windowlightstatusbar-property-programmatically

 

set windowlightstatusbar property programmatically

As you know we can set the windowLightStatusBar from xml by following codes. true i need to change this attribute true to false or fal...

stackoverflow.com

 

반응형

'Android' 카테고리의 다른 글

[안드로이드 / Kotlin] startActivityForResult 대체  (0) 2021.09.05
[안드로이드 / Kotlin] 코드로 문자열 밑줄 표현하기  (0) 2021.09.04
[안드로이드 / Kotlin] 뒤로가기 두번 눌러서 종료하기  (0) 2021.08.31
[안드로이드 / Kotlin] Array와 ArrayList 변환  (0) 2021.08.31
[안드로이드 / Kotlin] 라디오버튼 Dialog  (0) 2021.08.31
'Android' 카테고리의 다른 글
  • [안드로이드 / Kotlin] startActivityForResult 대체
  • [안드로이드 / Kotlin] 코드로 문자열 밑줄 표현하기
  • [안드로이드 / Kotlin] 뒤로가기 두번 눌러서 종료하기
  • [안드로이드 / Kotlin] Array와 ArrayList 변환
서주냥
서주냥
간단한 것도 기록하는 습관을 가지자
  • 서주냥
    DroidLog
    서주냥
  • 전체
    오늘
    어제
    • 전체보기 (58)
      • 알고리즘 (12)
        • 백준 (4)
        • 프로그래머스 (5)
        • 개념 (3)
      • Android (43)
        • Compose (1)
      • Java (2)
      • Kotlin (1)
  • 링크

    • GitHub
  • 인기 글

  • 태그

    viewmodel
    reified
    안드로이드
    블루투스
    viewpager2
    알고리즘
    뷰모델
    코틀린
    다이나믹 프로그래밍
    Coroutine Flow
    debounce
    SnackBar
    최단 경로
    코루틴
    백준
    ConstraintLayout
    RecyclerView
    이진 탐색
    BLE
    textunit
    FusedLocationProviderClient
    벨만 포드
    Coroutine
    Hilt
    클린 아키텍처
    프로그래머스
    Clean Architecture
    자바
    투 포인터
    moshi
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
서주냥
[안드로이드 / Kotlin] windowLightStatusBar
상단으로

티스토리툴바