夜间模式UI调整
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.ckkj.water.utils.manager;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2026/5/17
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
|
||||
public class ThemeManager {
|
||||
public static final String PREF_NAME = "theme_preferences";
|
||||
public static final String KEY_THEME_MODE = "theme_mode";
|
||||
|
||||
public static final int MODE_FOLLOW_SYSTEM = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||
public static final int MODE_LIGHT = AppCompatDelegate.MODE_NIGHT_NO;
|
||||
public static final int MODE_DARK = AppCompatDelegate.MODE_NIGHT_YES;
|
||||
|
||||
public static void setCurrentTheme(Context context, int themeMode) {
|
||||
SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
pref.edit().putInt(KEY_THEME_MODE, themeMode).apply();
|
||||
}
|
||||
|
||||
public static int getCurrentTheme(Context context) {
|
||||
SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
return pref.getInt(KEY_THEME_MODE, MODE_FOLLOW_SYSTEM);
|
||||
}
|
||||
|
||||
public static boolean isAppThemeLight(Context context){
|
||||
boolean isLight = false;
|
||||
SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
int code = pref.getInt(KEY_THEME_MODE, MODE_FOLLOW_SYSTEM);
|
||||
if(code == AppCompatDelegate.MODE_NIGHT_NO){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void applyTheme(int themeMode) {
|
||||
AppCompatDelegate.setDefaultNightMode(themeMode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user