Android 5.x features Overview three

Source: Internet
Author: User

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

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.