android系统修改深色模式(Dark theme) 默认值

2022年12月25日13:28:21

android9 android10 修改深色模式(Dark theme) 默认值

方法1

frameworks/base/core/res/res/values/config.xml

    <!-- Control the default night mode to use when there is no other mode override set.
         One of the following values (see UiModeManager.java):
             0 - MODE_NIGHT_AUTO
             1 - MODE_NIGHT_NO
             2 - MODE_NIGHT_YES
    -->
    <integer name="config_defaultNightMode">1</integer>

方法2

UiModeManager mUiModeManager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE);
mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES); // 深色模式(黑暗模式)
// mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); // 普通模式

需要权限 android.Manifest.permission.MODIFY_DAY_NIGHT_MODE

  • 作者:呈叙墨客
  • 原文链接:https://blog.csdn.net/mowwwcom/article/details/119210075
    更新时间:2022年12月25日13:28:21 ,共 588 字。