3

Hello so im working on a Music Player for android and i wanted help on making the background color the same as the album art of the playing song kind of like Sony Walkman.So can somebody please show how can it be done or at least get me on track on how it should be done.

I started Android recently so go easy on Me,and sorry for bad english

ray chamoun
  • 97
  • 2
  • 8
  • how are you going decide which pixel of the image is to be chosen for the background color? – Sagar Pilkhwal Sep 04 '14 at 18:56
  • http://stackoverflow.com/questions/7807360/how-to-get-pixel-colour-in-android http://stackoverflow.com/questions/6272859/getting-the-pixel-color-value-of-a-point-on-an-android-view-that-includes-a-bitm these links will help you hopefully. – Awais Sep 04 '14 at 19:34
  • Thank you for your quick response i want the dominant color of the image to be chosen for background and thanks Awais for the links i will check them out – ray chamoun Sep 04 '14 at 19:39

1 Answers1

3

You can use the v7 palette support library. It includes the Palette class, which lets you extract prominent colors from an image.

https://developer.android.com/reference/android/support/v7/graphics/Palette.html

Example

enter image description here

build.gradle

compile 'com.android.support:palette-v7:23.4.0'

Activity or fragment

public void updatePlayerBar(Bitmap bitmap) {
    Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
        public void onGenerated(Palette palette) {
            Palette.Swatch swatch = palette.getVibrantSwatch();
            if (swatch == null) swatch = palette.getMutedSwatch(); // Sometimes vibrant swatch is not available
            if (swatch != null) {
                // Set the background color of the player bar based on the swatch color
                mContent.setBackgroundColor(swatch.getRgb());

                // Update the track's title with the proper title text color
                mTitle.setTextColor(swatch.getTitleTextColor());

                // Update the artist name with the proper body text color
                mArtist.setTextColor(swatch.getBodyTextColor());
            }
        }
    });
}
Andrew Terekhine
  • 1,431
  • 19
  • 17