0

So I got this button and this ColorView on my .xml layout as you see in the left snapshoot, I want to fill the background of the ColorView square with the color chosen by the user in the dialog that you see on the right snapshoot.

enter image description hereenter image description here

My .xml code:

 <Button android:id="@+id/color_button" style="@style/buttonStyle" android:layout_width="280sp" android:layout_height="wrap_content" android:layout_alignBottom="@+id/color_view" android:layout_alignParentStart="true" android:layout_marginStart="13dp" android:onClick="showColorPickerDialog" android:text="Color" /> <es.lost2found.lost2foundUI.pickerUI.ColorView android:id="@+id/color_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="18dp" android:background="@color/otherUserMsgColor"> </es.lost2found.lost2foundUI.pickerUI.ColorView> 

The onClick method called on the button is this one:

public void showColorPickerDialog(View v) { ColorPickerUI colorpicker = new ColorPickerUI(); colorpicker.build() .title(R.string.color_dialog_title) .colorPreset(Color.BLACK) .allowCustom(true) .show(this, "dialog"); } 

I'm using the QuadFlask ColorPicker, I don't know if there's a method to do what I want, I've been searching on the repository and I didn't find it.

If there's any way to get what I want with other colorPicker let me know please, any help will be apreciated!

2 Answers 2

2

You need to add listener , which will be triggered when a color is either selected or positive button is pressed so use it like

public void showColorPickerDialog(View v) { ColorPickerUI colorpicker = new ColorPickerUI(); colorpicker .title(R.string.color_dialog_title) .colorPreset(Color.BLACK) .allowCustom(true)// change color on continuous selection .addOnColorChangedListener(new OnColorChangedListener() { @Override public void onColorChanged(int selectedColor) { findViewById(R.id.color_button).setBackgroundColor(selectedColor); } })// change color on selection .addOnColorSelectedListener( new OnColorSelectedListener() { @Override public void onColorSelected(int selectedColor) { findViewById(R.id.color_button).setBackgroundColor(selectedColor); } }) .build().show(this, "dialog"); } 
Sign up to request clarification or add additional context in comments.

2 Comments

I get an error on setPositiveButton "Cannot resolve method setPositiveButton(java.lang.String, anonymous com.flask.colorpicker.builder.ColorPickerClickListener)"
I am glad that I could help..happy coding
1

finally I got it, I've used onColorSet() method on my ColorPicker class, I put here the code in case someone need it

View view = getActivity().findViewById(R.id.color_view); view.setBackgroundColor(mSelectedColor); 

All I have to do was use the variable mSelectedColor and setBackground with it. Thank you so much to @Pavneet_Singh for your help, I'm sure someone will use your code!

1 Comment

I didn't know that you are using it in a fragment but glad that you found the solution

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.