你好,我正在为 android 开发音乐播放器,我需要帮助使背景颜色与正在播放的歌曲的专辑艺术相同,有点像索尼随身听。所以有人可以告诉我如何做到这一点或在至少让我了解应该如何完成。
我最近开始使用 Android,所以请放轻松,抱歉英语不好
最佳答案
您可以使用 v7 调色板支持库。它包含 Palette 类,可让您从图像中提取突出的颜色。
https://developer.android.com/reference/android/support/v7/graphics/Palette.html
示例
build.gradle
compile 'com.android.support:palette-v7:23.4.0'
Activity 或 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());
}
}
});
}
关于android - 更改 View 的背景以匹配专辑封面的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673021/