简体   繁体   中英

Change background color of floating action button using my image palette

Here is my code that I have used to retrieve color from palette. I am able to get the color but unable to set as background color of floating action button.

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

I think you should use

getRGB(int x, int y)

instead of getRGB().

It returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.

No Backgroundcolor named property for floatingAction Button. you can change it using

app:backgroundTint="@color/YOURCOLOR"

For this you have to import:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM