Android Status Bar transparent with Navigation Drawer - Appbar elevation

后端 未结 3 1493
-上瘾入骨i
-上瘾入骨i 2021-01-07 06:03

I am working on an app with Material Design Guidelines. I have a boilerplate app created by Android Studio. For some reason the status bar has a little gradient at the botto

3条回答
  •  一生所求
    2021-01-07 06:13

    The answer provided by Khizar Hayat is almost correct, but there's a better solution. Using the xml attribute

    app:elevation="0dp"
    

    in the toolbar removes the shadow on the status bar, but it also removes the bottom shadow of the toolbar, because the elevation is now set to zero, so the toolbar is at the same level of the background. Per the Google Material Design Guidelines, the Toolbar (or the AppBar) has a resting elevation of 4dp. You can check all the elevations provided by Google here: Elevation and shadows - Google Material Design Guidelines

    So, if you want to keep the standard elevation of the Toolbar and also remove the shadow in the status bar, there's a really simple solution.

    Now you probably have a layout like this:

    
    
    
        
    
            
    
                    
    
            
    
            .....
    
        
    
        
    
    
    

    This layout is one of the most used patterns to achieve this type of Navigation Drawer. You can see that both the DrawerLayout and the CoordinatorLayout have an xml attribute "android:fitsSystemWindows" setted to "true".

    The most simple way to remove the shadow on the status bar is to leave the attribute as it is in the DrawerLayout and set

    android:fitsSystemWindows="false"
    

    in the CoordinatorLayout. This will solve your problem.

提交回复
热议问题