首页 > 新闻资讯

preferencecategory(SwitchPreference使用)

preferencecategory(switchpreference使用)

1,布局

<?xmlversion="1.0"encoding="utf-8"?><preferencescreenxmlns:android="http://schemas.android.com/apk/res/android"><preferencecategoryandroid:summary="选择想要切换的皮肤"android:title="皮肤切换"><switchpreferenceandroid:key="buildinnightmode"android:summary="应用内换肤"android:title="夜间模式"/><switchpreferenceandroid:key="assetsnightmode"android:summary="插件式换肤"android:title="夜间模式"/><switchpreferenceandroid:key="sdcardnightmode"android:summary="指定sdcard路径"android:title="夜间模式"/></preferencecategory></preferencescreen>

2,java

publicclasssettingsfragmentextendspreferencefragment{publicstaticfinalstringbuild_in_night_mode_key="buildinnightmode";publicstaticfinalstringassets_night_mode_key="assetsnightmode";publicstaticfinalstringsdcard_night_mode_key="sdcardnightmode";privateswitchpreferencembuildinnightmodepreference;privateswitchpreferencemassetsnightmodepreference;privateswitchpreferencemsdcardnightmodepreference;@overridepublicvoidoncreate(@nullablebundlesavedinstancestate){super.oncreate(savedinstancestate);addpreferencesfromresource(r.xml.setting_preferences);mbuildinnightmodepreference=(switchpreference)findpreference(build_in_night_mode_key);mbuildinnightmodepreference.setonpreferencechangelistener(newpreference.onpreferencechangelistener(){@overridepublicbooleanonpreferencechange(preferencepreference,objectnewvalue){massetsnightmodepreference.setchecked(false);msdcardnightmodepreference.setchecked(false);booleanboolvalue=(boolean)newvalue;if(boolvalue){skincompatmanager.getinstance().loadskin("night",null,skincompatmanager.skin_loader_strategy_build_in);}else{skincompatmanager.getinstance().restoredefaulttheme();}returntrue;}});massetsnightmodepreference=(switchpreference)findpreference(assets_night_mode_key);massetsnightmodepreference.setonpreferencechangelistener(newpreference.onpreferencechangelistener(){@overridepublicbooleanonpreferencechange(preferencepreference,objectnewvalue){mbuildinnightmodepreference.setchecked(false);msdcardnightmodepreference.setchecked(false);booleanboolvalue=(boolean)newvalue;if(boolvalue){skincompatmanager.getinstance().loadskin("night.skin",null,skincompatmanager.skin_loader_strategy_assets);}else{skincompatmanager.getinstance().restoredefaulttheme();}returntrue;}});msdcardnightmodepreference=(switchpreference)findpreference(sdcard_night_mode_key);msdcardnightmodepreference.setonpreferencechangelistener(newpreference.onpreferencechangelistener(){@overridepublicbooleanonpreferencechange(preferencepreference,objectnewvalue){mbuildinnightmodepreference.setchecked(false);massetsnightmodepreference.setchecked(false);booleanboolvalue=(boolean)newvalue;if(boolvalue){skincompatmanager.getinstance().loadskin("night.skin",null,customsdcardloader.skin_loader_strategy_sdcard);}else{skincompatmanager.getinstance().restoredefaulttheme();}returntrue;}});}}

运行以后

preferencecategory(SwitchPreference使用)

原文标题:preferencecategory(SwitchPreference使用),如若转载,请注明出处:https://www.tzjingsheng.com/news/12227.html
免责声明:此资讯系转载自合作媒体或互联网其它网站,「豪运号」登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,文章内容仅供参考。