Add elevation/shadow on toolbar for pre-lollipop devices

前端 未结 8 1249
猫巷女王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:56

    I think the best solution is to put a gradient shadow view below the toolbar and manipulate with visibility depends on device sdk.

    toolbar.xml

     
        
    
            
    
                
    
            
    
            
    
        
    

    toolbar_shadow.xml

    
    
        
    
    

    MainActivity.class

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            findViewById(R.id.shadow_view).setVisibility(View.VISIBLE);
          }
    

提交回复
热议问题