The material design style is described in the previous section, which we introduce palette.
In the long stream of Android development, the UI is becoming the focus of Google's development. The above mentioned Android 5.x uses palette to extract colors, so that the theme dynamically applies to the current page tone, so that the entire app color tone more harmonious unity.
There are several types of extract tones that are built into Android, as shown below.
1. Vibrant (energetic)
2. Vibrant Dark (vibrant black)
3. Vibrant light (vibrant bright)
4. Muted (soft)
5, muted dark (soft black)
6, muted light (soft bright)
The development team was able to use the API provided by palette, allowing us to get the corresponding hue from the Bitmap and modify the current theme tones. Using Palette first requires referencing dependencies in Android Studio, clicking F4 on the project list, and then adding Com.android.support in the Dependencies tab of module Setting: palette-v7:21.0.2 reference, re-sync the project. You can create a Palette by passing a Bitmap object to Palette and calling its palette.generate () static method or the Palette.generateasync () method. Next, you can use the Getter method to retrieve the appropriate hue, which is the hue we have listed in the list above.
There are different ways to extract colors from different shades. The code is as follows:
Palette.getvibrantswatch ();p alette.getdarkvibrantswatch ();p alette.getlightvibrantswatch (); Palette.getmutedswatch ();p alette.getdarkmutedswatch ();p alette.getlightmutedswatch ();
The following example demonstrates the tonal effect tones extracted using the Getdarkvibrantswatch () method to change the hue of the status bar, as shown in the code below.
Bitmap Bitmap =Bitmapfactory.decoderesource (Getresources (), r.drawable.test); //Create a Palette objectPalette.generateasync (Bitmap,NewPaletteasynclistener () {@Override Public voidongenerated (Palette Palette) {palette.swatch Swatch=Palette.getdarkmutedswatch ();//Getactionbar (). Setbackgrounddrawable (//New Colordrawable (Swatch.getrgb ()));window window =GetWindow (); Window.setstatusbarcolor (Swatch.getrgb ()); } });
The effect of the code is as follows:
Android 5.x features Overview three