gpt4 book ai didi

安卓应用调色板

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:20 25 4
gpt4 key购买 nike

我正在尝试使用 android Material 设计的调色板功能,但我在应用它时遇到了一些麻烦。

我已成功生成调色板,现在我正尝试将调色板传递给应用它的函数。

我遇到的问题是,当我将调色板传递给 applyPalette 函数时,没有任何方法像 palette.getDarkMutedColor().getRgb() 、 palette.getVibrantColor( ).getRgb() 正在填充调色板中的值。

除了将调色板传递给函数之外,我所遵循的教程没有提及任何其他内容,这样做会填充方法

这是生成器函数和应用函数,有人能看出为什么这不起作用吗?

代码

private void colorize(Bitmap photo) {
Palette palette = new Palette.Builder(photo).generate();
applyPalette(palette);
}

private void applyPalette(Palette palette) {
getWindow().setBackgroundDrawable(new ColorDrawable(palette.getDarkMutedColor().getRgb()));

TextView titleView = (TextView) findViewById(R.id.title);
titleView.setTextColor(palette.getVibrantColor().getRgb());

TextView descriptionView = (TextView) findViewById(R.id.description);
descriptionView.setTextColor(palette.getLightVibrantColor().getRgb());

colorRipple(R.id.info, palette.getDarkMutedColor().getRgb(),
palette.getDarkVibrantColor().getRgb());
colorRipple(R.id.star, palette.getMutedColor().getRgb(),
palette.getVibrantColor().getRgb());

View infoView = findViewById(R.id.information_container);
infoView.setBackgroundColor(palette.getLightMutedColor().getRgb());

AnimatedPathView star = (AnimatedPathView) findViewById(R.id.star_container);
star.setFillColor(palette.getVibrantColor().getRgb());
star.setStrokeColor(palette.getLightVibrantColor().getRgb());
}

最佳答案

使用 picassopalette 第三方库并将其导入到您的项目中,然后使用以下代码:

try {
ContextWrapper cw = new ContextWrapper(OtherUserProfileScreenActivity.this);
Picasso.with(this).load(image + ".jpg").placeholder(R.drawable.ic_loading).error(R.drawable.ic_error).into(imageView, PicassoPalette.with(Image + ".jpg", imageView).use(PicassoPalette.Profile.MUTED_DARK).intoCallBack(new BitmapPalette.CallBack() {
@Override
public void onPaletteLoaded(Palette palette) {

int mutedColor = palette.getMutedColor(R.attr.colorPrimary);
mCollapsingToolbarLayout.setContentScrimColor(mutedColor);
}
}));
} catch (OutOfMemoryError e) {
e.printStackTrace();
System.gc();
}

关于安卓应用调色板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33475799/

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