ambilwarna icon indicating copy to clipboard operation
ambilwarna copied to clipboard

Default value doesn't work

Open kraxarn opened this issue 7 years ago • 4 comments

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

kraxarn avatar Jul 04 '17 19:07 kraxarn

Can you post your code which sets the default value?

denisk20 avatar Jul 05 '17 09:07 denisk20

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.

kraxarn avatar Jul 05 '17 13:07 kraxarn

I'll take a look, hopefully soon. Let me know if you come up with a pull request, it will be highly appreciated.

denisk20 avatar Jul 05 '17 13:07 denisk20

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.

kraxarn avatar Jul 05 '17 15:07 kraxarn