shamanland / floating-action-button

Implementation of a circular button made of paper that lifts and emits ink reactions on press.
http://shamanland.github.io/floating-action-button
Apache License 2.0
371 stars 88 forks source link

Color changes back to default on press or leaving activity #18

Closed demandedcross closed 9 years ago

demandedcross commented 9 years ago

Not sure if this is a bug or something I'm doing wrong. I'm setting the color usin palette after glide has finished loading an image resource from a url into the view. The color is set correctly but then changes to a default gray color after it is clicked or just before the activity disappears and stays that color.

ok3141 commented 9 years ago

Do you want to change the color of button during runtime? If not, try to customize it via styles, like here.

It's hard to understand what you are doing without code examples.

demandedcross commented 9 years ago

Yeah it's during runtime, using the Palette api to get the colour from a bitmap loaded from a url.

Glide.with(App.me).load(coverUrl).asBitmap().thumbnail(0.2f).animate(R.anim.abc_fade_in).into(new BitmapImageViewTarget(movieDetailCoverImage) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                        super.onResourceReady(bitmap, anim);

                        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
                            public void onGenerated(Palette palette) {
                                // Do something with colors...
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    getWindow().setStatusBarColor(palette.getDarkVibrantColor(Color.GRAY));
                                }

                                fab.setColor(palette.getVibrantColor(Color.GRAY));
                                fab.initBackground();

                            }
                        });
                    }
                });
ok3141 commented 9 years ago

Try to add single line before fab.setColor(...):

fab.setColorStateList(null);

If this line will help, than I will fix the bug.

demandedcross commented 9 years ago

That fixes it :)

ok3141 commented 9 years ago

Okay, you may use this workaround, and I will fix it soon.