V7 Compatibility Pack--Use of palette palette

Source: Internet
Author: User

Four previous articles about the use of the V7 Compatibility Pack Recyclerview
android V7 Compatibility Pack Recyclerview use (iv)--click event Handling in different ways
use of the Android V7 Compatibility Pack Recyclerview (iii)--use of the layout manager
use of the Android V7 Compatibility Pack Recyclerview (ii)
use of the Android V7 Compatibility Pack Recyclerview (i)
Today, I do not intend to see a v7 compatibility package in another library palette, learning the next, what the role of this library, white is to use it to achieve dynamic color settings.

Material design encourages developers to use dynamic colors, especially when we have a rich picture resource to display, the palette library in the V7 Compatibility Pack is born, which allows us to extract a portion of the color from a picture to control our UI elements, creating an immersive experience , the extracted colors will include vibrant and soft tones that will make the foreground text color the best visual effect

Before we use the Palette library, let's find this dependency file from the SDK, which is in the following position

.. \sdk\extras\android\support\v7\palette\libs\android-support-v7-palette.jar

We create a project and copy it to the Libs directory.

There are two ways to use palette, namely

    • Synchronization of
    • of asynchronous
Synchronization method

public static Palette Generate (Bitmap Bitmap)

Use this method to ensure that you have access to the thread associated with the picture loading
The method uses the default number of color bits (default_calculate_number_colors=16), and we can specify the number of bits using the two-parameter method

public static Palette Generate (Bitmap Bitmap, int numcolors)

Numcolors the best value is depending on the picture resource type, for the landscape map, 12-16 best, for the face of the picture, the value needs to increase to 24-32 is the best. This increase in value increases the time of calculation, and if there is no special requirement, use the default value to
Here is an example of how a synchronous method is used

 Bitmap map=BitmapFactory.decodeResource(getResources(), R.drawable.qblog_fig3); Palette generate = Palette.generate(map); Swatch vibrantSwatch = generate.getVibrantSwatch();TextView tv=(TextView)findViewById(R.id.title);tv.setTextColor(vibrantSwatch.getRgb());
Async methods
publicstaticgenerateAsync(Bitmap bitmap, PaletteAsyncListener listener)  publicstaticgenerateAsync(            finalfinalintfinal PaletteAsyncListener listener)

The difference between the two methods and the two methods of synchronization is the same, the two methods are asynchronous and need to pass in a listener, the prototype of the listener is

publicinterface PaletteAsyncListener {        /**         * Called when the {@link Palette} has been generated.         */        void onGenerated(Palette palette);    }

The following is an example of the use of an async method

new Palette.PaletteAsyncListener() {    @Override    publicvoidonGenerated(Palette palette) {         Palette.Swatch vibrant = palette.getVibrantSwatch();          ifnull) {              // If we have a vibrant color, update the title TextView              titleView.setBackgroundColor(vibrant.getRgb());              titleView.setTextColor(vibrant.getTitleTextColor());          }    }});
Properties of the Palette

Palette.swatch is a sample of color extraction that can be extracted to contain the color content we need

    • Returns a vibrant color. Palette.getvibrantswatch ()
    • Returns a vibrant dark color. Palette.getdarkvibrantswatch ()
    • Returns a vibrant bright color. Palette.getlightvibrantswatch ()
    • Returns a soft color. Palette.getmutedswatch ()
    • Returns a soft, dark color. Palette.getdarkmutedswatch ()
    • Returns a soft bright color. Palette.getlightmutedswatch ()

Vibrant colours and vibrant dark colors are the most used by developers, depending on your own

Swatch Properties
    • Getpopulation (): Returns the total number of pixels represented by the sample
    • getRGB (): Returns an RGB color value
    • GETHSL (): Returns a HSL color value.
    • Getbodytextcolor (): Returns a color value that is appropriate for the color of the content body
    • Gettitletextcolor (): Returns a color value that is suitable for heading color

The text color of the title tends to be high transparency and low contrast, the font should also be larger, body text color will tend to high opacity and high contrast.

Below we use, according to personal habits, first paste, as for the code ... Too slag, do not post, interested in their own download source to see it.

SOURCE download
http://download.csdn.net/detail/sbsujjbcy/8563237

V7 Compatibility Pack--Use of palette 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.