Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove shadow below AppBarLayout widget android

When using AppBarLayout widget in design support library, a shadow appears on the bottom of the toolbar. How can I remove that shadow?

like image 618
Abdul Rehman Avatar asked Aug 21 '15 06:08

Abdul Rehman


People also ask

How do I get rid of shadow below toolbar on Android?

By default, android provides shadow for action bar. This example demonstrates How to remove shadow below the action bar. Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 - Add the following code to res/layout/activity_main.

How do I remove elevation from AppBar?

You can remove the elevation from Material UI's AppBar by setting the elevation prop to 0.

What is AppBarLayout?

AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures. Children should provide their desired scrolling behavior through AppBarLayout.


2 Answers

Simply use app:elevation="0dp" inside "AppBarLayout" to remove the shadow. It has always worked for me. Hope it works for you.

like image 101
danialzahid94 Avatar answered Sep 21 '22 07:09

danialzahid94


this problem only occurs when api version >= 21, try below codes:

appBar.setOutlineProvider(null); 

remember to check api version


EDIT :

Below is the source code of setOutlineProvider.

   /**      * Sets the {@link ViewOutlineProvider} of the view, which generates the Outline that defines      * the shape of the shadow it casts, and enables outline clipping.      * <p>      * The default ViewOutlineProvider, {@link ViewOutlineProvider#BACKGROUND}, queries the Outline      * from the View's background drawable, via {@link Drawable#getOutline(Outline)}. Changing the      * outline provider with this method allows this behavior to be overridden.      * <p>      * If the ViewOutlineProvider is null, if querying it for an outline returns false,      * or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.      * <p>      * Only outlines that return true from {@link Outline#canClip()} may be used for clipping.      *      * @see #setClipToOutline(boolean)      * @see #getClipToOutline()      * @see #getOutlineProvider()      */     public void setOutlineProvider(ViewOutlineProvider provider) {         mOutlineProvider = provider;         invalidateOutline();     } 

It is said that If the ViewOutlineProvider is null, if querying it for an outline returns false, or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.

So, if you want to remove shadow, you'd better use this method instead of setting app:elevation. It seems like that changing the elevation to remove shadow is a kind of side effect. And changing the elevation may cause some other problems in some cases.

like image 29
Liu Teng Avatar answered Sep 23 '22 07:09

Liu Teng