Setting Elevation in XML on AppCompat CardView on Android 5.0

后端 未结 5 2068
梦如初夏
梦如初夏 2020-12-12 16:07

From what I understand, early in the preview stage there seemed to be no way to set elevation in XML only on CardViews without a hack in Java. Now that the offi

5条回答
  •  攒了一身酷
    2020-12-12 16:35

    You have to use the cardElevation attribute.
    Androidx libraries:

    You can use the MaterialCard included in the official Material Components library:

    implementation 'com.google.android.material:material:1.x.x'
    

    And in your layout:

        
    

    Or the CardView in the androidx packages:

    implementation 'androidx.cardview:cardview:1.x.x'
    

    And in your layout:

         
    

    OLD support library:

    
    

提交回复
热议问题