ambilwarna
ambilwarna copied to clipboard
Default value doesn't work
When setting a defaultValue in the xml file for the settings, it doesn't show or set it until the dialog is opened. There, the default color is shown.
No color shown instead of the set one
But when you open it
Can you post your code which sets the default value?
In my preference xml file I have
<PreferenceCategory android:title="Colors">
<yuku.ambilwarna.widget.AmbilWarnaPreference
android:key="color_yellow"
android:defaultValue="0xffff00"
android:title="Yellow" />
</PreferenceCategory>
Which I then load in a PreferenceFragment in an onCreate method.
I'll take a look, hopefully soon. Let me know if you come up with a pull request, it will be highly appreciated.
So I tried playing around with this a little bit more and found a "workaround" for it.
Within my preferences fragment, I tried doing
((AmbilWarnaPreference) getPreferenceScreen().findPreference("color_yellow")).forceSetValue(0xffff00);
This, as I thought, didn't work and it just set that checkerboard. However, if I instead try
((AmbilWarnaPreference) getPreferenceScreen().findPreference("color_yellow")).forceSetValue(Color.YELLOW);
It sets the color just fine.
Found a "fix", if I instead set defaultValue to -256 (which is the value of Color.YELLOW), it sets the default value just fine.