How to get AppCompatDelegate current mode if default is auto

后端 未结 3 1146
鱼传尺愫
鱼传尺愫 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:00

    You can get the current mode using the following code,

    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
            // Night mode is not active, we're in day time
        case Configuration.UI_MODE_NIGHT_YES:
            // Night mode is active, we're at night!
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
            // We don't know what mode we're in, assume notnight
    }
    

    The following article by Chris Banes explains it nicely.

提交回复
热议问题