android - 更改 View 的背景以匹配专辑封面的颜色

标签 android background-color albumart

你好,我正在为 android 开发音乐播放器,我需要帮助使背景颜色与正在播放的歌曲的专辑艺术相同,有点像索尼随身听。所以有人可以告诉我如何做到这一点或在至少让我了解应该如何完成。

我最近开始使用 Android,所以请放轻松,抱歉英语不好

最佳答案

您可以使用 v7 调色板支持库。它包含 Palette 类,可让您从图像中提取突出的颜色。

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'

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/

相关文章:

java - 在 Android 应用程序中从互联网下载专辑封面

android - 如何使用 MediaStore.Audio.Albums.ALBUM_ART 显示专辑封面?

应用程序中的 android:screenOrientation 标签不起作用

android - .gif 图像作为源在 Windows kivy 程序中运行良好。通过 kivy Launcher 运行显示 gif 图像的背景

css - 来自十六进制 RGB 值的 CSS 中的半透明背景颜色

Android ListView 项目背景颜色

android - Job Scheduler 和 WorkManager 在应用被终止时被销毁

android - 从 fragment 中获取当前 Activity

jquery - 使用 JQuery 将三种不同的背景颜色应用于同一类的三个 div

android - picasso 无法加载专辑封面