Android 使用“我的图像”调色板更改浮动操作按钮的背景色

Android 使用“我的图像”调色板更改浮动操作按钮的背景色,android,floating-action-button,Android,Floating Action Button,这是我用来从调色板中检索颜色的代码。我可以获得颜色,但无法设置为浮动操作按钮的背景色 Palette.Swatch vibrantSwatch = palette.getDarkVibrantSwatch(); Palette.Swatch vibrantSwatch2 = palette.getLightVibrantSwatch(); if ( vibrantSwatch != null && vibrantSwatch2 != null) { //fb repre

这是我用来从调色板中检索颜色的代码。我可以获得颜色,但无法设置为浮动操作按钮的背景色

Palette.Swatch vibrantSwatch = palette.getDarkVibrantSwatch();
Palette.Swatch vibrantSwatch2 = palette.getLightVibrantSwatch();

if ( vibrantSwatch != null && vibrantSwatch2 != null) {
    //fb represents my floating action button
    fb.setBackgroundTintList(ColorStateList.valueOf(vibrantSwatch2.getRgb()));
}
我认为你应该使用

getRGB(整数x,整数y)

而不是getRGB()


它返回默认RGB颜色模型(TYPE_INT_ARGB)和默认sRGB颜色空间中的整数像素。

没有为floatingAction按钮命名的Backgroundcolor属性。您可以使用

app:backgroundTint="@color/YOURCOLOR"
为此,您必须导入:

xmlns:app="http://schemas.android.com/apk/res-auto"

添加相关标记并改进格式删除不需要的空格