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(); }
详细操作描述第⼀步:⾃定义属性
第三步:在布局⽂件中配置使⽤对应属性
注意textColorAttr、backgroundAttr、backgroundDrawableAttr三个属性。如需当前页⾯⽴即刷新,需填加相应属性。第四步:页⾯调⽤java代码 @Override protected void onCreate(Bundle savedInstanceState) { //1. 在要⽴即切换效果的页⾯调⽤此⽅法 tance().init(this,).setTheme(this, me, heme); //在其他页⾯调⽤此⽅法
//me(this, me, heme); te(savedInstanceState); setContentView(ty_main); //2.设置切换夜间活⽇间模式 //Day(this, me);//切换⽇间模式 //Night(this, heme);//切换夜间模式 } @Override protected void onDestroy() { roy(); //3. 在onDestroy调⽤ ory(); }
代码调⽤三步,即可开始夜间之旅。如果页⾯有新创建的视图要加⼊夜间模式控制,安卓源码调⽤: //添加额外view⾄夜间管理 // tance().addBackgroundColor(toolbar, rimary); //tance().addBackgroundDrawable(view,ccent); // tance().addTextColor(view,ccent);
如果在改变夜间模式时有其他⾮标准定义的属性时,可在Day或Night之后调⽤如下代码给相关属性赋值: TypedValue attrTypedValue = rTypedValue(this, Color);
leTextColor(getResources().getColor(ceId));以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689217797a222499.html
评论列表(0条)