Add elevation/shadow on toolbar for pre-lollipop devices

前端 未结 8 1272
猫巷女王i
猫巷女王i 2020-11-28 05:39

I updated my android app to the new material design, but I also wanted to add some shadow or elevation to the Toolbar. There seem to be some (hacky) ways of doing it via ima

8条回答
  •  隐瞒了意图╮
    2020-11-28 05:54

    A simple solution, when using CoordinatorLayout, is to anchor an ImageView with the "shadow" just below the AppBarLayout, or Toolbar. This even works with CollapsingToolbarLayout, and it's correctly rendered atop the "content":

    
      
        
      
      
      
    
    

    Create a res/layout/app_bar_shadow.xml file, which will only be use on pre-Lollipop devices:

    
    

    Create an "empty" res/layout-v21/app_bar_shadow.xml file, used for Android 5+ devices:

     
    

    Finally, an appropriate res/drawable/shadow_app_bar.xml:

    
      
      
    
    

提交回复
热议问题