调色板库:如何为Palette Swatch Color添加透明度?

Wid*_*ide 2 android android-palette android-graphics

如何为调色板的样本添加透明度值?就像我将颜色(swatch.getRGB())添加到线性布局一样,它显示纯色.而且我不想使用alpha,因为它会使布局中的其他项目也变得透明.

我的代码片段:

Palette palette = Palette.from(myBitmap).generate();
Palette.Swatch swatch1 = palette.getDarkVibrantSwatch();
int color = swatch1.getRgb();
thatLayout.setBackgroundColor(color)
Run Code Online (Sandbox Code Playgroud)

Gre*_*ryK 5

使用android支持实用程序类:

thatLayout.setBackgroundColor(ColorUtils.setAlphaComponent(swatch.getRgb(), alpha));
Run Code Online (Sandbox Code Playgroud)