CardView elevation not working on Android 5.1.1

非 Y 不嫁゛ 提交于 2019-11-30 10:35:36

To make it both compatible above or below api 21, you need to specify app:cardUseCompatPadding="true" in your support CardView.

<android.support.v7.widget.CardView
        app:cardElevation="4dp"
        app:cardUseCompatPadding="true"
        app:cardMaxElevation="6dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
</android.support.v7.widget.CardView>

Just simply add this code to your Card View in xml file!

    card_view:cardUseCompatPadding="true"

You have to import card_view with Alt+Enter ! And code below will be import in top !.

  xmlns:card_view="http://schemas.android.com/apk/res-auto"

You'll see elevation is working on android 5 or 5+ .

Remove below line if you used in AndroidManifest.xml

android:hardwareAccelerated="false"

remove this line from <application ...> </application> in AndroidManifest.xml file

android:hardwareAccelerated="false"

change to

android:hardwareAccelerated="true"

for more details Hardware acceleration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!