How to disable the shadow around card view in android

人盡茶涼 提交于 2019-12-03 09:17:47

use this attribute in XML

card_view:cardElevation="0dp"

and remember add xmlns:card_view="http://schemas.android.com/tools" in your root layout.

OR you can call cardView.setCardElevation(0) to disable shadow programmatically.

cardView.setElevation() method and CardView attribute android:elevation will throw java.lang.NoSuchMethodError in platform before Android 5.0

Try to put the elevation in Xml.

app:cardElevation="0dp"

OR

cardView.setCardElevation(0);

And check you are using the latest CardView library.

Brahem Mohamed

Just put this line inside your CardView:

app:cardElevation="0dp"

Hope it will help you.

You can have it in XML like:

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp"
    app:cardElevation="0dp"
    app:cardCornerRadius="0.5dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    >
   </android.support.v7.widget.CardView>

hope it helps you !!!

You should first add this to the your parent layout

xmlns:card_view="http://schemas.android.com/tools"

then set the elevation like this

card_view:cardElevation="0dp"

try like this may help you,

CardView cardView = (CardView) v.findViewById(R.id.cardView);
cardView.setCardElevation(0);
 <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardElevation="0dp"
        app:cardCornerRadius="2dp">
....`
 </android.support.v7.widget.CardView>

You have to use the following attributes

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="0dp"
    app:cardCornerRadius="0.5dp"
    app:cardPreventCornerOverlap="false"
    >
   </android.support.v7.widget.CardView>

CardView sets its own elevation during initialization, which will override whatever you set from XML. You should file this as a bug at chek this

@Override
public void initialize(CardViewDelegate cardView, Context context, int backgroundColor,
        float radius) {
    cardView.setBackgroundDrawable(new RoundRectDrawable(backgroundColor, radius));
    View view = (View) cardView;
    view.setClipToOutline(true);
    view.setElevation(context.getResources().getDimension(R.dimen.cardview_elevation));
}

In my case, only setting of background alpha with suggested elevation and backgroundColor hide shadow border:

 this.setCardElevation(0);
 this.setCardBackgroundColor(getContext().getResources().getColor(android.R.color.transparent));
 this.getBackground().setAlpha(0);

use app:cardElevation="0dp", don't use app:elevation="0dp"

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