-1

I want to implement the same feature as we can see in WhatsApp, while seeing a person's profile the color of the status bar changes based upon the color of the image.

TheSohan
  • 442
  • 3
  • 18
  • Whats Whatsapp? I don't have it on my iphone. How I am supposed to verify the situation you are describing? This is the reason you should clearly mention what you want now say like "I want what XYZ does". – Rohit5k2 May 10 '19 at 10:47
  • check this out https://drive.google.com/file/d/1UC25E2z80zbEaEAD7NbtV-RwjKCNQ3Qw/view?usp=sharing – TheSohan May 10 '19 at 10:54
  • 3
    Possible duplicate of [Finding the dominant color of an image in an Android @drawable](https://stackoverflow.com/questions/8471236/finding-the-dominant-color-of-an-image-in-an-android-drawable) – jeprubio May 10 '19 at 10:57

3 Answers3

2

It's called Pallete, use the below function, just pass your bitmap image

  private void setUpPalette(Bitmap bitmap) {
   // you passed your Bitmap image;
    Palette.from(bitmap).
            generate(new Palette.PaletteAsyncListener() {
                @Override
                public void onGenerated(Palette palette) {
                    if (palette != null) {

                       //default color is yellow
                       // set the color to toolbar, whatever
                        int extColor = palette.getVibrantColor(ContextCompat.getColor(MainActivity.this, R.color.yellow));
                         if (getWindow() != null) {
                                getWindow().setStatusBarColor(ContextCompat.getColor(this, extColor));
                                }
                    } else {
                         if (getWindow() != null) {
                                    getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.fail_safe));
                                                    }
                    }
                }
            });
}
hemen
  • 1,460
  • 2
  • 16
  • 35
1

You have to use the Palette library to get the dominant color:

// Generate palette asynchronously and use it on a different
// thread using onGenerated()
public void changeStatusBarColorAsync(Bitmap bitmap) {
  Palette.from(bitmap).generate(new PaletteAsyncListener() {
    public void onGenerated(Palette p) {
      // Use generated instance
      Palette.Swatch vibrant = p.getVibrantSwatch();
      int color = ContextCompat.getColor(getContext(),R.color.default_title_background);
      if(vibrant != null){
        color = vibrantSwatch.getTitleTextColor();
      }
      getWindow().setStatusBarColor(ContextCompat.getColor(this, color));
    }


  });
}
FedeFonto
  • 354
  • 3
  • 14
0

https://stackoverflow.com/a/28145358/9186913 you will find the most vibrant color in the image and you can change the getWindow().setStatusBarColor(getResources().getColor(R.color.color));

raj kavadia
  • 926
  • 1
  • 10
  • 30