android判断是否是深色模式

判断系统是否是深色模式和判断当前app是否是深色模式不一样。

系统是深色模式,但此app自己代码单独设置了不是深色模式,
(用下列代码设置成非深色模式

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);


此时

    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    int uiMode = context.getResources().getConfiguration().uiMode
    Log.d("TEST","uiMode = "+Integer.toHexString(uiMode)+" H");
    Log.d("TEST","getNightMode() = "+Integer.toHexString(uiModeManager.getNightMode() )+" H");
    if ((uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
        Log.d("TEST","night");
    } else {
       Log.d("TEST","not night");
    }
    if (uiModeManager.getNightMode()==UiModeManager.MODE_NIGHT_YES) {
        Log.d("TEST","night");
    } else {
        Log.d("TEST","not night");
    }

log:

D TEST   : uiMode = 11 H
D TEST   : getNightMode() = 2 H
D TEST   : not night
D TEST   : night
结论
int uiMode = context.getResources().getConfiguration().uiMode
if ((uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES){}

判断此app应用了何种模式。

UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
if (uiModeManager.getNightMode()==UiModeManager.MODE_NIGHT_YES) {}

判断系统应用了何种模式

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值