Android 4.4 remove shadow from CardView

前端 未结 3 1985
野性不改
野性不改 2020-12-21 16:23

I tried to remove the shadow from the Cardview.
I used android support v7 Cardview on android v4.4.2

My layout look:



        
相关标签:
3条回答
  • 2020-12-21 17:04

    Just add below code to cardview tag

    app:cardElevation="0dp"
    

    and don't forget to add

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

    UPDATE

    Also try this put below codes in cardview

    app:cardElevation="0dp"
    app:cardMaxElevation="0dp"
    app:cardCornerRadius="1dp"
    app:cardUseCompatPadding="true"
    app:cardPreventCornerOverlap="false"
    android:background="@null"
    

    The app:cardCornerRadius should be bigger than 0(>0) otherwise throw exception

    I'm using API 28 support library

    implementation 'com.android.support:cardview-v7:28.0.0'

    0 讨论(0)
  • 2020-12-21 17:11

    I just fixed this problem by using a relative layout instead. Simply change the CardView value to a relative layout and you will essentially get the same result, but without the shadow

    0 讨论(0)
  • 2020-12-21 17:16

    You cannot remove the shadow from the cardview in 4.4. Anything below 5.0 elevation does nothing so all the cardview is in 4.4 is an image with a shadow

    To create a card with a shadow, use the card_view:cardElevation attribute. CardView uses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see Maintaining Compatibility.

    http://developer.android.com/training/material/lists-cards.html#CardView

    0 讨论(0)
提交回复
热议问题