夜间模式

来源:互联网 发布:电力系统仿真软件综述 编辑:程序博客网 时间:2024/04/28 18:20
  //夜间白天

                int mode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
                SharedPreferences sp = getSharedPreferences("night", Context.MODE_PRIVATE);
                if (mode == Configuration.UI_MODE_NIGHT_YES) {
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("night", false).commit();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                } else if (mode == Configuration.UI_MODE_NIGHT_NO) {
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("night", true).commit();
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                }
原创粉丝点击