일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 쓰레드 이미지 다운로드
- 직장영어
- 쓰레드 비디오 다운로드
- conventional NFR
- 자료구조
- 특수문자
- 특수기호
- meta threads
- 메타 쓰레드
- Realtime Database
- skeleton architecture
- jenkins
- Android
- 영어회화
- endless scrolling
- 안드로이드
- 파이썬
- django
- 라이브아카데미
- re-engineering
- 젠킨스
- non conventional NFR
- firestore
- git
- RecyclerView
- Python
- 객치지향프로그래밍
- 이모티콘
- Firebase
- cloud firestore
Archives
- Today
- Total
Owl Life
AndroidQ 다크테마 적용방법 본문
반응형
안드로이드 Q의 새로운 피처인 다크테마 적용 방법에 대하여 알아보겠습니다.
시스템에서 다크테마 적용은 설정 - 디스플레이 메뉴에서 적용이 가능합니다.
앱에서는,
1. style - theme의 parent를 Theme.AppCompat.DayNight 로 수정
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
2. theme의 parent를 DayNight 로 설정하지 못하는 경우에는 android:forceDarkAllowed 속성 추가
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:forceDarkAllowed">true</item>
</style>
3. 코드 레벨에서 강제로 ON/OFF
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<View>(R.id.change_mode_btn).setOnClickListener { toggleNightMode() }
renderModeState()
}
fun renderModeState() {
var output: TextView = findViewById(R.id.output_tv)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) {
output.text = "NIGHT_MODE_OFF"
} else if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
output.text = "NIGHT_MODE_ON"
}
}
fun toggleNightMode() {
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
} else if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
}
configuration에서 uiMode 값의 마스킹을 통해서 현재 앱이 night mode가 적용되어있는지 아닌지를 읽을 수 있습니다.
public static final int UI_MODE_NIGHT_NO = 16;
public static final int UI_MODE_NIGHT_YES = 32;
이 값에 따라서 나이트 모드를 적용할 것인지는 AppCompatDelegate.setDefaultNightMode api를 사용하면 적용이 가능합니다.
<나이트 모드 OFF>
<나이트 모드 ON>
전체 소스코드
반응형
'Android Dev > dev' 카테고리의 다른 글
안드로이드 Dalvik과 ART, JIT과 AOT 차이점 (0) | 2019.10.09 |
---|---|
[개발자 폰트] 나눔고딕코딩 에서 D2 Coding 글꼴로 변경하다. (0) | 2017.12.03 |
Comments