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