http://www.jianshu.com/p/24e9cf03cdcf
btn.setOnClickListener(new View.OnClickListener() {
@Overridepublic void onClick(View v) {
SharedPreferences sp=getSharedPreferences("sdsdd",MODE_PRIVATE);
boolean isNight = sp.getBoolean("night", false);
if (isNight) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
sp.edit().putBoolean("night", false).commit();
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
sp.edit().putBoolean("night", true).commit(); } recreate();
}
});