gpt4 book ai didi

java - 调色板(Android 支持 v22)不生成色板

转载 作者:行者123 更新时间:2023-11-30 02:10:25 26 4
gpt4 key购买 nike

首先,我从未使用过 Palette,当我想开始使用它时,我看到所有教程和博客都在谈论 v21 而不是 v22。

我的问题是我有一个 Swatch(在 swatch 数组 [palette.getSwatches().get(0)] 的位置 0)总是返回黑色(标题和正文),这是我正在使用的示例这个,也许是错的,但我正在复制这个 https://developer.android.com/reference/android/support/v7/graphics/Palette.html

        Palette.from(BitmapFactory.decodeResource(getResources(),R.drawable.prueba2)).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
text.setTextColor(palette.getVibrantSwatch().getBodyTextColor());
text.setBackgroundColor(palette.getVibrantSwatch().getTitleTextColor());
}
});

当我启动这个应用程序时(我有一个带有 textView 和 ImageView 的 Activity )它关闭时说这个

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.support.v7.graphics.Palette$Swatch.getBodyTextColor()' on a null object reference
at com.alfondo.projectpalette.MainActivity.onCreate(MainActivity.java:33)"

编辑:这是我的可绘制对象。 (我不能发布 img)http://imgur.com/YGV9xVS

最佳答案

首先创建图像的位图,然后使用毕加索调色板获取图像的颜色并将该颜色设置为可折叠工具栏

  // get bitmap of image and generate toolbar color by passing bitmap to palette


Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.nature);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
// get muted color from bitmap using palette and set this to collapsible toolbar

@Override
public void onGenerated(Palette palette) {
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimary)));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimaryDark)));
}
});

关于java - 调色板(Android 支持 v22)不生成色板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30189086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com