Appcompat v21 Toolbar elevation pre-lollipop

后端 未结 10 626
你的背包
你的背包 2020-12-23 13:33

First off, I know that this question has been asked before, but it hasn\'t been answered before. I hope someone can give me an answer.

In my application, I use the T

10条回答
  •  甜味超标
    2020-12-23 14:23

    Using CardView container for toolbar is a bad idea.

    CardView is heavy, especially for low end devices.

    The best way is to put a gradient Shadow view below the toolbar. Shadow view must be a direct child to the coordinator layout. ie. The appbar which contains toolbar and shadow View must be siblings.

    Add this view component to your layout.

     
    

    The drawable toolbar_shadow.xml

    
    
    
    
    

    This will solve the problems in pre-lollipop devices. But we don't want this shadow in lollipop and above devices so make visibility to gone in devices with lollipop and above.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            findViewById(R.id.gradientShadow).setVisibility(View.GONE);
    }
    

    Done.

提交回复
热议问题