How to get AppCompatDelegate current mode if default is auto

后端 未结 3 1139
鱼传尺愫
鱼传尺愫 2020-12-15 19:37

I have activity like this:

package com.nkdroid.daynighttheme;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.supp         


        
3条回答
  •  感情败类
    2020-12-15 20:08

    If you are a kotlin developer, then you can use the code below to check which mode your app is in..

    val mode = context?.resources?.configuration?.uiMode? and Configuration.UI_MODE_NIGHT_MASK
    when (mode) {
        Configuration.UI_MODE_NIGHT_YES -> {}
        Configuration.UI_MODE_NIGHT_NO -> {}
        else -> {} //covers Configuration.UI_MODE_NIGHT_UNDEFINED
    }
    

    For more about the dark theme modes see;

    https://github.com/googlesamples/android-DarkTheme/

提交回复
热议问题