How to implement the Material-design Elevation for Pre-lollipop

前端 未结 7 1354
南旧
南旧 2020-11-27 11:44

Google has shown some nice ways that elevation effect are shown on Lollipop here.

android:elevation=\"2dp\"

for buttons,

an         


        
7条回答
  •  有刺的猬
    2020-11-27 12:42

    You can't mimic the elevation on pre-Lollipop with a official method.

    You can use some drawables to make the shadow in your component. Google uses this way in CardView for example.

    The ViewCompat.setElevation(View, int) currently creates the shadow only on API21+. If you check the code behind, this method calls:

    API 21+:

      @Override
        public void setElevation(View view, float elevation) {
            ViewCompatLollipop.setElevation(view, elevation);
        }
    

    API < 21

    @Override
    public void setElevation(View view, float elevation) {
    
    }
    

提交回复
热议问题