0

I have set both the CardView's background and FrameLayout's to transparent yet the result is still a white color bg.

Is this some default behavior? What should I change to my xml layout file for having a transparent bg ?

Layout file :

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    card_view:cardBackgroundColor="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp">


    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="140dp"
        tools:layout_gravity="center">

        <TextView
            android:id="@+id/dayID"
            android:textColor="@color/link_text_material_light"
            android:textSize="26dp"
            android:layout_marginLeft="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/monthID"
            android:textColor="@color/link_text_material_light"
            android:layout_marginLeft="60dp"
            android:textSize="26dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <TextView
            android:id="@+id/splashID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/link_text_material_light"
            android:textSize="26dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:padding="20dp"
            tools:text="Hero text" />

        <TextView
            android:id="@+id/sunbathMinsID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/link_text_material_light"
            android:textSize="26dp"
            android:layout_gravity="bottom"
            android:gravity="center"
            android:padding="20dp"
            tools:text="Hero text" />
    </FrameLayout>


    </android.support.v7.widget.CardView>
vicolored
  • 815
  • 2
  • 10
  • 20

1 Answers1

0

A transparent background can be obtained for any number of views within your XML. This is a decent explanation for an imageview. Set transparent background of an imageview on Android

Cardviews are a lot the same but have a little different attribute and are explained very well with the "app:cardBackgroundColor= "@android:color/transparent"" See this post for that type of attribute. Transparent background on CardView - Android

Setting your cardView and the subsequent FrameLayout both to transparent will definitely get the job done and make both views transparent. However, the activity will always have a solid background. The Activity only doesn't have a solid background when you set a resource as the background and the views placed within that Activity will show the current background if they are set to transparent as seen in the links above.

Therefore, even though you have set your "views" to transparent, the Activity will always need a color or image to show the in background. Meaning that, yes you will still have a white background behind your cardView, unless you change that color.

EPAgg
  • 99
  • 1
  • 12