我尝试在CollapsingToolbarLayout的contentScrim中设置渐变颜色,但只需要简单的颜色
尝试使用这样的位图,但通过IllegalArgumentException: Bitmap is not valid
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.bar_bg);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch vibrant =
palette.getVibrantSwatch();
int mutedColor = palette.getVibrantSwatch().getRgb();
if (vibrant != null) {
// If we have a vibrant color
// update the title TextView
collapsingToolbarLayout.setBackgroundColor(mutedColor);
// mutedColor = palette.getMutedColor(R.attr.colorPrimary);
collapsingToolbarLayout.setStatusBarScrimColor(palette.getDarkMutedColor(mutedColor));
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(mutedColor));
}
}
});
答案 0 :(得分:0)
试试这个:
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(vibrantSwatch.getRgb()));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(vibrantSwatch.getRgb()));
}
});