styles - Changing theme of entire Android application using RadioButtons -
hello have 4 custom defined styles in styles.xml , trying use radiogroup in order select overall style of entire application.
<style name="bluetheme" parent="android:theme.light.notitlebar.fullscreen"> <item name="android:windowbackground">@color/blue_background</item> <item name="android:textcolorprimary">@color/blue_text</item> </style> <style name="redtheme" parent="android:theme.light.notitlebar.fullscreen"> <item name="android:windowbackground">@color/red_background</item> <item name="android:textcolorprimary">@color/red_text</item> </style> <style name="greentheme" parent="android:theme.light.notitlebar.fullscreen"> <item name="android:windowbackground">@color/green_background</item> <item name="android:textcolorprimary">@color/green_text</item> </style> <style name="bwtheme" parent="android:theme.light.notitlebar.fullscreen"> <item name="android:windowbackground">@color/bw_background</item> <item name="android:textcolorprimary">@color/bw_text</item> </style>
here code actual handling of radiogroup selection, had attempted checkboxes that's why names checkboxes.
bluecheckbox = (radiobutton) findviewbyid(r.id.bluecheckbox); redcheckbox = (radiobutton) findviewbyid(r.id.redcheckbox); greencheckbox = (radiobutton) findviewbyid(r.id.greencheckbox); bwcheckbox = (radiobutton) findviewbyid(r.id.bwcheckbox); radiogroup radiogroup = (radiogroup) findviewbyid(r.id.themeradiogroup); radiogroup.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup group, int checkedid) { // checkedid radiobutton selected switch(checkedid) { case r.id.bluecheckbox: getapplication().settheme(r.style.bluetheme); break; case r.id.redcheckbox: getapplication().settheme(r.style.redtheme); break; case r.id.greencheckbox: getapplication().settheme(r.style.greentheme); break; case r.id.bwcheckbox: getapplication().settheme(r.style.bwtheme); break; } } });
the problem having though overall style not change. in androidmanifest.xml file defaulted theme
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/bluetheme" >
but despite that, when run app theme not bluetheme. bluetheme not have colors displayed on app's activities. reason theme being displayed has gray text , dark gray / blackish background, colors displayed background colors of buttons manually set in each individual layout/activity_myactiviitesthathavebuttons xml file. not sure doing wrong, can please try provide assistance? thank help
p.s: not sure if matters believe min api set 8, believe professors wants set as.
create base activity overrides oncreate , sets theme activity based on preference. make activities override preference. preference set when user changes selection on radio button.
more information can found on similar question answered before:
Comments
Post a Comment