Android - How to detect if night mode is on when using AppCompatDelegate.MODE_NIGHT_AUTO

前端 未结 5 684
天涯浪人
天涯浪人 2020-12-01 02:53

I\'m using Androids built in day/night mode functionality and I\'d like to add an option to my app for AppCompatDelegate.MODE_NIGHT_AUTO

I\'m having a p

5条回答
  •  执念已碎
    2020-12-01 03:18

    int nightModeFlags =
        getContext().getResources().getConfiguration().uiMode &
        Configuration.UI_MODE_NIGHT_MASK;
    switch (nightModeFlags) {
        case Configuration.UI_MODE_NIGHT_YES:
             doStuff();
             break;
    
        case Configuration.UI_MODE_NIGHT_NO:
             doStuff();
             break;
    
        case Configuration.UI_MODE_NIGHT_UNDEFINED:
             doStuff();
             break;
    }
    

提交回复
热议问题