An analysis of the problems encountered in the manufacture of the Android color editor _android

Source: Internet
Author: User
Android does not have its own color editor, in order to let the user intuitive choice of color, made such a control, the effect diagram is as follows:



Top color bar for the main color bar, the user can choose the roughly needed color, below is the color balance adjustment, you can adjust brightness.

Background color is easy to implement, with gradientdrawable in the primary color between the gradient can be, the top of the background color is always unchanged. The lower balance adjusts as long as the gradient is between white, selected color and black, and the lower color changes with the color above.

Color bar its own control because of the need to drag, directly integrated with the Android Seekbar can be implemented, just replace the default progressdrawable can.

The only strange problem encountered was:

I provide an array of colors for the lower color tone:

Copy Code code as follows:

Private int[] Colorarr;


Inside storage: White, upper selected color and black
When the top selection changes, I change the second color in the Colorarr array, which is the selected color, and calls the control's Invalidate method, which, oddly, does not change the color or the original color.

At this point, if you drag the bottom scroll bar, even if you drag only 1%, you can change to the correct color.
I'm guessing that Android's Seekbar will not redraw its progress background color when the schedule doesn't change.
Then use the following techniques to manually change to a certain progress, and then change back, so you can redraw its progress background color:

Copy Code code as follows:

/**
* Set the color balance of the middle color
* @param color
*/
public void Setbalencecolor (int color)
{
This.color = color;
SetBackground ()//Reset the middle color in the progressdrawable
This.invalidate ();
int max = This.getmax ();
int currentprogress = this.getprogress (); Backup Progress
This.setprogress (max-currentprogress)//modify to some other progress
This.setprogress (currentprogress);//Restore Progress
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.