Check Mobile App
Read now
Start a Project

Changing background to image accent color

Save

Dynamic color is an important part of your mobile app especially when your app is full of images. With the release of android lollipop there is a support library using which you can change your application background and text colors according to your images and that is new Palette Support Library. Using the support library you can access a Bitmap image and extract colors from it. The library provides you Vibrant and muted tones of the image. It also provides you the foreground colors for readablity of your text.

Firstly add the dependency to build.gradle file

Now take a Bitmap object of your image and generate a palette object. Be sure thst the Bitmap is not null or Recycled because if it is then it will throw a IllegalArgumentException.

You can have six colors profiles and you can get them from there getter methods. Developers generally use vibrant colors but usage is strictly based on users choice. These methods returns their corresponding int rgb color.

  1. Vibrant – getVibrantColor()
  2. Vibrant Light – getLightVibrantColor()
  3. Vibrant Dark – getDarkVibrantColor()
  4. Muted – getMutedColor()
  5. Muted Light – getLightMutedColor()
  6. Muted dark – getDarkMutedColor()

Palette Swatch:

Represents a color swatch generated from an image’s palette. The corresponding (int) rgb can be retrieved from getRgb(). The Palette.Swatch class gives you the vibrated and muted tones of image but also give the text color that can be uded on that Swatch by getBodyTextColor(). It also includes the number of pixels of that color in the image.

You can get all the six colors using the built-in getter methods as

Here are the background an example when backgroung of layout is changed corresponding to image using getDarkVibrantSwatch().

Color from getVibrabtColor()

Screenshot_2016-01-22-14-44-55

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • asdf
    Thanks sir
  • css.php

    The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

    Igor Souza

    Igor Souza

    Talk to Sales

    Global

    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home