Android 5.0--Palette

Source: Internet
Author: User

Palette is used to get the color content from the image resource.

The following is a tool class for using color values:
 Public classPaletteutils { Public Static intGetcolorwithdefault (Palette Palette,intDefaultColor) {Palette.swatch CurrentItem=NULL; if(CurrentItem = =NULL) {
Vibrant color CurrentItem=Palette.getvibrantswatch (); } if(CurrentItem = =NULL) {
Vibrant dark tones CurrentItem=Palette.getdarkvibrantswatch (); } if(CurrentItem = =NULL) {
Vibrant bright tones CurrentItem=Palette.getlightvibrantswatch (); } if(CurrentItem = =NULL) {//Soft tones
CurrentItem=Palette.getmutedswatch (); } if(CurrentItem = =NULL) {
Soft dark tones CurrentItem=Palette.getdarkmutedswatch (); } if(CurrentItem = =NULL) {
Soft bright tone CurrentItem=Palette.getlightmutedswatch (); } returnCurrentItem! =NULL?Currentitem.getrgb (): DefaultColor; } Privatepaletteutils () {Throw NewAssertionerror (); }}

The following is to get the color content from the bitmap, get is to get the color of different tones, and then through GETRGB () get the real color content required by the program,

Palette.generateasync is the method of getting the color inside the bitmap asynchronously, and the operation inside is the operation in the asynchronous thread.

Palette.generate () is not asynchronous and operates in the main thread.

Bitmap Bitmap =Bitmapfactory.decoderesource (Getresources (), Superawesomecardfragment.getbackgroundbitmapposition (Positi      ON)); //part of the palette    Palette.generateasync (Bitmap, new Palette.paletteasynclistener () {/** * callback method after extraction */ @Override public void ongenerated (Palette Palette) {Palette.swatch vibrant = Palette.getvibran Tswatch (); /* Interface Color UI uniformity processing, looks more material some */Mpagerslidingtabstrip.setbackgroundcolor (VIBRANT.GETRGB ()); Mpagerslidingtabstrip.settextcolor (Vibrant.gettitletextcolor ()); Where the status bar, cursor, the bottom navigation bar color needs to be deepened, or can not be added, the specific situation after the code description Mpagerslidingtabstrip.setindicatorcolor (Colorburn (VIBRANT.GETRG B ())); Mtoolbar.setbackgroundcolor (Vibrant.getrgb ()); if (Android.os.Build.VERSION.SDK_INT >=) {window window = GetWindow (); Obviously, these two goods are the new API only. Window.setstatusbarcolor (Colorburn (Vibrant.getrgb ())); Window.setnavigationbarcolor (Colorburn (Vibrant.getrgb ())); } } });  

Android 5.0--Palette

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.