ColorPickerView icon indicating copy to clipboard operation
ColorPickerView copied to clipboard

setInitialColor seems not working with BrightnessSlideBar on 2.3.0

Open riccardoch opened this issue 2 years ago • 3 comments

I'm using ColorPickerView and after the update setInitialColor doesn't update BrightnessSlideBar while setting the view in onCreate.

If I call setInitialColor in a second moment everything works. Maybe is something related with slider width calculations?

Anyway when setInitialColor works the slider of BrightnessSlideBar is out of bounds if brightness is 100%.

riccardoch avatar Oct 11 '23 16:10 riccardoch

My fix solution:

public class CustomBrightnessSlideBar extends BrightnessSlideBar {
    public CustomBrightnessSlideBar(Context context) {
        super(context);
    }

    public CustomBrightnessSlideBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomBrightnessSlideBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public CustomBrightnessSlideBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void onInflateFinished() {
        // In the original version, the selector is set to the default position at the slide bar end, 
        // which prevents the correct brightness position of the initial color from being set. 
        // Just ignore super.onInflateFinished.
    }
}

proninyaroslav avatar Feb 15 '25 18:02 proninyaroslav

Can confirm that brightness bar ignores initialColor and always on 100%. Any workarounds to fix it in builder initialization without using custom layouts?

n-apps avatar Jun 06 '25 20:06 n-apps

Can confirm that brightness bar ignores initialColor and always on 100%. Any workarounds to fix it in builder initialization without using custom layouts?

view.colorPickerView.post { view.colorPickerView.setInitialColor(color) } Just need to execute setInitialColor in the post

Spriteing avatar Jul 11 '25 08:07 Spriteing