Analysis of problems encountered during the preparation of the Android color editor

Source: Internet
Author: User

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
}
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.