Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set add background color to glide image

I'm using Glide for setting png images (with transparencies) in ImageView in this mode:

Glide.with(context).load(url)
                .crossFade()
                .placeholder(R.drawable.no_contest)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into((ImageView)container);

Is it possible to set the backgroundcolor of the image without setting the background color of ImageView ?

thanks

like image 380
Luca Romagnoli Avatar asked Oct 30 '22 08:10

Luca Romagnoli


1 Answers

LayerDrawable should be used:

.into(new SimpleTarget<GlideDrawable>() {

    @Override
    public void onResourceReady(GlideDrawable resource,
                                GlideAnimation<? super GlideDrawable> glideAnimation) {
        final ShapeDrawable background = new ShapeDrawable();
        background.getPaint().setColor("color here");
        final Drawable[] layers = {background, resource};

        container.setImageDrawable(new LayerDrawable(layers));
    }
});
like image 133
Akaki Kapanadze Avatar answered Nov 15 '22 05:11

Akaki Kapanadze