LoginSignup
0
0

More than 1 year has passed since last update.

Android ダークモード コードで判定

Last updated at Posted at 2021-11-23

内容

  • コードでダークモード判定をする

環境

  • 今回の内容を実践した私の環境です。
macOS Monterey 12.0.1
Android Studio Chipmunk 2021.2.1 Canary 4

結論

  • 下記のコードにより、ダークモード・ライトモード判定ができます!
judgeMode.kt
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    // SDKのバージョンがR以降である場合にダークモード設定が導入されたため、それを判定する
    if (context.theme.resources.configuration.isNightModeActive) {
        // ダークモードの場合にこのスコープに入る
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0