2017-02-16 80 views
0

这是我用来从调色板中检索颜色的代码。我能够获得颜色,但无法设置为浮动动作按钮的背景颜色。使用我的图像调色板更改浮动动作按钮的背景颜色

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())); 
} 
+0

添加相关标签,提高格式化 –

+0

删除不需要的空格:您可以使用

app:backgroundTint="@color/YOURCOLOR" 

对于这一点,你必须导入改变 –

回答

0

我认为你应该使用

的getRGB(INT X,int y)对

代替的getRGB()。

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

0

没有用于floatingAction Button的Backgroundcolor命名属性。

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