Hello I am am working on demo application in which i am using the card view of support library. By default it is adding shadow around it. I want to remove this shadow & shou
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);
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 !!!
try like this may help you,
CardView cardView = (CardView) v.findViewById(R.id.cardView);
cardView.setCardElevation(0);
If anyone is looking for kotlin answer then this worked for me
card_layout.cardElevation = 0F
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"