2014-09-04 51 views
1

您好,我正在为Android设计一款音乐播放器,并且我希望帮助您将背景颜色与播放歌曲的专辑封面相同随身听。所以有人可以告诉我们该怎么做,或者至少让我走上正确的轨道。更改视图的背景以匹配专辑封面的颜色

我最近开始的Android这样下去容易对我,对不起,英语不好

+0

你打算如何选择图像的哪个像素作为背景颜色? – 2014-09-04 18:56:16

+0

http://stackoverflow.com/questions/7807360/how-to-get-pixel-colour-in-android http://stackoverflow.com/questions/6272859/getting-the-pixel-color-这些链接将有助于你的希望。这些链接将帮助你有希望。 – Awais 2014-09-04 19:34:00

+0

感谢您的快速响应我希望图像的主色可以选择背景,并感谢Awais的链接,我会检查它们 – 2014-09-04 19:39:50

回答

1

可以使用V7调色板支持库。它包括调色板类,它允许您从图像中提取突出的颜色。

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

enter image description here

的build.gradle

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

活动或片段

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()); 
      } 
     } 
    }); 
}