Skip to content

Commit 6652f7f

Browse files
committed
Fix for setting DefaultValue as hex string
I have noticed that when you set defaultValue you can only set it as an actual color integer. 1. If you set it as hex string it crashes, as it expects integer 2. If you set it as reference to resources color, it persists 0 into shared preferences Method onGetDefaultValue was modified to look for a string and if it is not null, to use built in method to parse hex string into color integer and return it as default. Color hex can only be used with 6 or 8 chars. If the string is null, it will look for an integer and use it.
1 parent caf4eee commit 6652f7f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ColorPickerPreference/src/main/java/net/margaritov/preference/colorpicker/ColorPickerPreference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public ColorPickerPreference(Context context, AttributeSet attrs, int defStyle)
6868
protected Object onGetDefaultValue(TypedArray a, int index) {
6969
int colorInt;
7070
String mHexDefaultValue = a.getString(index);
71-
if (mHexDefaultValue != null) {
71+
if (mHexDefaultValue != null && mHexDefaultValue.startsWith("#")) {
7272
colorInt = convertToColorInt(mHexDefaultValue);
7373
return colorInt;
7474

0 commit comments

Comments
 (0)