Use of palette

Source: Internet
Author: User

(Reproduced, please indicate the source: http://www.kennethyo.me/post/android/palettechu-ji-shi-yong)


I believe many people have begun to pay attention to Android lollipop. The brand-new material design style is eye-catching. Material emphasizes bold shadows and highlight matching, referencing unexpected and vibrant colors.

We will talk about the palette updated by Android in the V7 package not long ago. Palette makes it easier for us to construct a colorful interface.bitmapTo obtain the color of the image.

Initialize palette

PaletteInitialize through a static method, and you need to inputbitmap, ThisbitmapWe want to obtain the bitmap of the color image.

Palette palette = Palette.generate(bitmap);

There is also an Asynchronous Method:

// Provides an asynchronous method called palette. generateasync (bitmap, new palette. paletteasynclistener () {@ override public void ongenerated (palette ){}});
Obtain Palette.Swatch

Obtain the correspondingPalette.Swatch,Palette.SwatchIs a carrier that contains the color we get

palette.getVibrantSwatch();palette.getMutedSwatch();palette.getLightVibrantSwatch();palette.getLightMutedSwatch();palette.getDarkVibrantSwatch();palette.getDarkMutedSwatch();
Pass Palette.SwatchObtain color

For Android,Palette.Swatch.getRgb()ReturnsintRGB color value. For example:

Textview TV1 = (textview) findviewbyid (R. id. TV1); // return a vibrant color tv1.settextcolor (palette. getvibrantswatch (). getrgb (); // return a soft color tv1.setbackgroundcolor (palette. getmutedswatch (). getrgb (); textview TV2 = (textview) findviewbyid (R. id. TV2); // return a vibrant bright color tv2.settextcolor (palette. getlightvibrantswatch (). getrgb (); // returns a soft bright tv2.setbackgroundcolor (palette. getlightmutedswatch (). getrgb (); textview TV3 = (textview) findviewbyid (R. id. TV3); // return a vibrant dark color tv3.settextcolor (palette. getdarkvibrantswatch (). getrgb (); // returns a gentle dark color tv3.setbackgroundcolor (palette. getdarkmutedswatch (). getrgb (); textview TV4 = (textview) findviewbyid (R. id. TV4); // return the color tv4.settextcolor (palette. getvibrantswatch (). gettitletextcolor (); // returns a color tv4.setbackgroundcolor (palette. getdarkmutedswatch (). getbodytextcolor ());

In general, palette is easy to use and there are no complicated methods, making it easier for us to develop the material style.
Demo address

Use of 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.