true为黑夜模式
//检查当前系统是否已开启暗黑模式 public static boolean getDarkModeStatus(Context context) {int mode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;return mode == Configuration.UI_MODE_NIGHT_YES;}
实现效果
昼白天 夜晚上
实现方法:
1、创建昼夜两种颜色color.xml资源文件
昼
<?xml version="1.0" encoding="utf-8"?>
<resources><color name="main_bg">#FFFFFF</color><color name="button_bg">#3988FB</color><color name="button_text_color">#FFFFFF</color><color name="text_color">#000000</color><color name="line_color">#FF0000</color></resources>
夜
<?xml version="1.0" encoding="utf-8"?>
<resources><color name="night_main_bg">#262f3c</color><color name="night_button_bg">#285FAF</color><color name="night_button_text_color">#A6BDDE</color><color name="night_text_color">#95A7C2</color><color name="night_line_color">#00FF00</color></resources>
2、创建皮肤style样式文件
3、调用module换肤工具类SkinEngine方法
public void setDaySkin(View view){SkinEngine.changeSkin(R.style.AppTheme);
}public void setNightSkin(View view){SkinEngine.changeSkin(R.style.AppNightTheme);
}
demo链接:Android换肤demo-Android代码类资源-CSDN下载
demo云盘链接:百度网盘-链接不存在
在线回复密码:QQ1085220040