I had this working before, but suddenly it decide to die on me and produce errors.
Here's what I have:
<ListPreference
android:defaultValue="#33B5E5"
android:entries="@array/colours"
android:entryValues="@array/colours_hex"
android:key="action_bar_colour"
android:summary="Change the background colour of the top bar."
android:title="Action Bar Colour" >
</ListPreference>
XML: <string-array name="colours"> <item name="Light Blue">Light Blue</item> <item name="Dark Blue">Dark Blue</item> <item name="Light Purple">Light Purple</item> <item name="Dark Purple">Dark Purple</item> <item name="Light Green">Light Green</item> <item name="Dark Green">Dark Green</item> <item name="Light Orange">Light Orange</item> <item name="Dark Orange">Dark Orange</item> <item name="Light Red">Light Red</item> <item name="Dark Red">Dark Red</item> <item name="Black">Black</item> </string-array> <string-array name="colours_hex"> <item name="Light Blue">#33B5E5</item> <item name="Dark Blue">#0099CC</item> <item name="Light Purple">#AA66CC</item> <item name="Dark Purple">#9933CC</item> <item name="Light Green">#99CC00</item> <item name="Dark Green">#669900</item> <item name="Light Orange">#FFBB33</item> <item name="Dark Orange">#FF8800</item> <item name="Light Red">#FF4444</item> <item name="Dark Red">#CC0000</item> <item name="Black">#000000</item> </string-array>
I have initiated the preference here in MainActivity:
PreferenceManager.setDefaultValues(this, R.layout.settings, false);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
String actionBarColourHex = sp.getString("action_bar_colour", "#33B5E5");
System.out.println(actionBarColourHex);
// Action bar
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color
.parseColor(actionBarColourHex)));
I'm receiving the error that it is unable to parse this colour. When I print out actionBarColourHex, I get the name "Light Blue" rather than the hex code, "#33B5E5." This exact code has previously worked for me before. I have tried cleaning the project and rebuilding it, as well as restarting both my computer and device. This is currently causing the whole application to fail to open due to this code being called in onCreate().
0 comments:
Post a Comment