Dimezis / BlurView

Dynamic iOS-like blur of underlying Views for Android
Apache License 2.0
3.48k stars 331 forks source link

How to add a shadow or elevation to BlurView? #196

Closed LinKav20 closed 1 year ago

Dimezis commented 1 year ago

Pretty much the same way as with other Views. Add a background, and set elevation. If you don't want to add a background, setting the outline provider to BOUNDS should also work

blurView.setOutlineProvider(ViewOutlineProvider.BOUNDS)
LinKav20 commented 1 year ago

It works. I wanted rounded corners and shadow.

I've tried to mixed it, but it failed.

Rounded cornes: (as readme) Background is rounded corners and no solid color and I set the elevation. Outline provider is ViewOutlineProvider.BACKGROUND In this variant I have a rounded corners shape and no shadow

Shadow: All the same as above but outline provider is ViewOutlineProvider.BOUNDS In this variant I have a rectangle shape and shadow

Unfortunatelly I have no idea how to mixed it

Dimezis commented 1 year ago

Right.

To work it around you can do something like this.

        blurView.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                blurView.getBackground().getOutline(outline);
                outline.setAlpha(1f);
            }
        });

I.e. it's still de-facto a BACKGROUND provider, but it fixes the 0 alpha outline of the transparent background, which also affects the alpha of the elevation shadow

Dimezis commented 1 year ago

I also just pushed this example to the sample app

LinKav20 commented 1 year ago

Thank you, everything worked out!