三行Android代码实现白天夜间模式流畅切换

三行Android代码实现白天夜间模式流畅切换

2023年7月13日发(作者:)

三⾏Android代码实现⽩天夜间模式流畅切换Usage xml android:background= ?attr/zzbackground app:backgroundAttr= zzbackground //如果当前页⾯要⽴即刷新,这⾥传⼊属性名称 ⽐如ground 传zzbackground即可 android:textColor= ?attr/zztextColor app:textColorAttr= zztextColor//

演⽰效果

Usage xml

android:background="?attr/zzbackground" app:backgroundAttr="zzbackground"//如果当前页⾯要⽴即刷新,这⾥传⼊属性名称 ⽐如ground 传zzbackground即可

android:textColor="?attr/zztextColor" app:textColorAttr="zztextColor"//如需⽴即刷新页⾯效果 同上

java @Override protected void onCreate(Bundle savedInstanceState) { // 在要⽴即切换效果的页⾯调⽤此⽅法 tance().init(this,).setTheme(this, me, heme); //在其他页⾯调⽤此⽅法

//me(this, me, heme); te(savedInstanceState); setContentView(ty_main); //添加额外view⾄夜间管理 // tance().addBackgroundColor(toolbar, rimary); //tance().addBackgroundDrawable(view,ccent); // tance().addTextColor(view,ccent); // 设置切换 //Day(this, me); //Night(this, heme); }

@Override protected void onDestroy() { roy(); // 在onDestroy调⽤ ory(); }

详细操作描述第⼀步:⾃定义属性 第⼆步:配置夜间style⽂件