Android does not have its own color editor. In order to allow users to select colors intuitively, this control is made as follows:
The color bar above is the main color bar. You can select the desired color. below is the balance adjustment of the color to adjust the brightness.
The background color is easy to implement. You can use GradientDrawable to gradually change the color between the primary colors. The background color on the top remains unchanged. Below the balance adjustment as long as the gradient between the white, selected color and black, the color below changes with the color above.
As you need to drag the color bar control, you can directly integrate the SeekBar that comes with Android to achieve this. You only need to replace the default ProgressDrawable.
The only strange problem encountered is:
I provide a color array for the color tone below:
Copy codeThe Code is as follows: private int [] colorArr;
Inside: white, selected color above and black
After the selected color changes, I changed the second color in the colorArr array, that is, the selected color, and called the invalidate method of the control. The strange thing is that the control did not change the color, or the original color.
At this point, if you drag the scroll bar below, even if you only drag 1%, it can change to the correct color.
I guess: When the progress of the SeekBar in Android is not changed, the background color of the progress will not be re-painted.
Then, use the following technique to manually change to a certain progress and then change it back so that the background color of the progress can be re-painted:
Copy codeThe Code is as follows :/**
* Set the middle color of the color balance.
* @ Param color
*/
Public void SetBalenceColor (int color)
{
This. color = color;
SetBackground (); // reset the middle color in ProgressDrawable
// This. invalidate ();
Int max = this. getMax ();
Int currentProgress = this. getProgress (); // backup progress
This. setProgress (max-currentProgress); // modify to another progress
This. setProgress (currentProgress); // restore progress
}