Jono
Jono

Reputation: 18118

cardview not setting background to transparent

Hi i have a cardview located at the center of a view and i want to make its background transparent. But it does not seem to do it and has a white background

Here is my xml

<android.support.v7.widget.CardView
    android:id="@+id/boundaryBox"
    android:layout_width="270dp"
    android:layout_height="176dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    card_view:cardBackgroundColor="@android:color/transparent"
    card_view:cardElevation="0dp"
    card_view:cardCornerRadius="14dp" />

Upvotes: 2

Views: 2950

Answers (1)

Chetan Ansel
Chetan Ansel

Reputation: 468

Have you checked that you parent layout have any background, As If you try below code, cardview would be transparent.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    android:padding="@dimen/dp_16"
    tools:context=".MainActivity">

    <android.support.v7.widget.CardView
        android:id="@+id/boundaryBox"
        android:layout_width="match_parent"
        android:layout_height="176dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:cardBackgroundColor="@android:color/transparent"
        app:cardElevation="16dp"
        app:cardCornerRadius="14dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="test"/>
    </android.support.v7.widget.CardView>
</RelativeLayout>

Please try this.

Upvotes: 3

Related Questions