How to disable the shadow around card view in android

后端 未结 12 1775
陌清茗
陌清茗 2021-02-01 11:34

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

相关标签:
12条回答
  • 2021-02-01 12:26

    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));
    }
    
    0 讨论(0)
  • 2021-02-01 12:27

    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);
    
    0 讨论(0)
  • 2021-02-01 12:32

    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 !!!

    0 讨论(0)
  • 2021-02-01 12:34

    try like this may help you,

    CardView cardView = (CardView) v.findViewById(R.id.cardView);
    cardView.setCardElevation(0);
    
    0 讨论(0)
  • 2021-02-01 12:38

    If anyone is looking for kotlin answer then this worked for me

    card_layout.cardElevation = 0F
    
    0 讨论(0)
  • 2021-02-01 12:40

    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"

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