android – 将RecyclerView CardView背景更改为透明

问题简短版本:

I want to make my CardView and RecyclerView background transparent, so
the fragment/activity background should become visible.

解释:

我有一个活动A与背景图像和片段B被替换在它的Framelayout,在片段B我有recyclerView与CardView现在的问题是我想让每个背景透明所以只有CardView将可见与活动的实际背景

RecyclerView看起来像这样(这些白色背景应该是透明的):
recyclerView_Card

活性(A)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:backgroundTint="@android:color/transparent"/>

片段(B)RecyclerView

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:backgroundTint="@android:color/transparent"
    android:background="@android:color/transparent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        tools:listitem="@layout/layout_video_item"
        android:backgroundTint="@android:color/transparent"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView
        android:id="@+id/tv_not_found"
        android:text="No Media Found Yet"
        android:layout_gravity="center"
        android:gravity="center"
        android:visibility="gone"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.CoordinatorLayout>

CardView /项目布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="3dp"
    android:layout_marginStart="3dp"
    android:layout_marginTop="3dp"
    android:background="@android:color/transparent">

    <android.support.v7.widget.CardView
        style="@style/CardView.Light"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardUseCompatPadding="true"
        android:background="@android:color/transparent"
        android:backgroundTint="@android:color/transparent"
        app:cardCornerRadius="5dp"
        android:padding="0dp"
        app:cardElevation="0dp"
        tools:ignore="ContentDescription">

        <android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:background="@color/colorAccent">

            <ImageView
                android:id="@+id/media_image"
                android:layout_width="100dp"
                android:layout_height="0dp"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@android:color/darker_gray" />

            <ImageButton
                android:id="@+id/ib_delete"
                android:layout_width="30dp"
                android:layout_height="40dp"
                android:background="#00FFFFFF"
                android:padding="12dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:srcCompat="@drawable/ic_delete_white_24dp" />

            <ImageButton
                android:id="@+id/share_button"
                android:layout_width="30dp"
                android:layout_height="40dp"
                android:background="#00FFFFFF"
                android:padding="12dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/ib_delete"
                app:srcCompat="@drawable/ic_share_white_24dp" />

            <TextView
                android:id="@+id/tv_video_name"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:ellipsize="marquee"
                android:singleLine="true"
                android:text="Title Test"
                android:textAppearance="@style/TextAppearance.AppCompat.Large.Inverse"
                android:textColor="@color/colorPrimaryText"
                app:layout_constraintEnd_toStartOf="@+id/tv_ribbon"
                app:layout_constraintStart_toEndOf="@+id/media_image"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tv_ribbon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/holo_red_light"
                android:ellipsize="marquee"
                android:fontFamily="monospace"
                android:padding="3dp"
                android:singleLine="true"
                android:text="New"
                android:textColor="@color/colorIcons"
                android:textSize="14sp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tv_path"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="5dp"
                android:ellipsize="marquee"
                android:singleLine="true"
                android:text="subtitle test"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/media_image"
                app:layout_constraintTop_toBottomOf="@+id/tv_video_name" />

            <ImageView
                android:id="@+id/iv_is_audio"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginBottom="8dp"
                android:layout_marginStart="5dp"
                android:layout_marginTop="8dp"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/media_image"
                app:layout_constraintTop_toBottomOf="@+id/tv_duration"
                app:srcCompat="@drawable/ic_settings_voice_black_24dp" />

            <ImageView
                android:id="@+id/iv_is_video"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_marginStart="5dp"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="@+id/iv_is_audio"
                app:layout_constraintStart_toEndOf="@+id/iv_is_audio"
                app:layout_constraintTop_toTopOf="@+id/iv_is_audio"
                app:srcCompat="@drawable/ic_theaters" />

            <ImageView
                android:id="@+id/iv_is_gif"
                android:layout_width="35dp"
                android:layout_height="30dp"
                android:layout_marginStart="5dp"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="@+id/iv_is_video"
                app:layout_constraintStart_toEndOf="@+id/iv_is_video"
                app:layout_constraintTop_toTopOf="@+id/iv_is_video"
                app:srcCompat="@drawable/ic_gif" />

            <TextView
                android:id="@+id/tv_duration"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:layout_marginTop="8dp"
                android:text="0:00"
                app:layout_constraintStart_toEndOf="@+id/media_image"
                app:layout_constraintTop_toBottomOf="@+id/tv_path" />

            <TextView
                android:id="@+id/tv_size"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:text="0 MB"
                app:layout_constraintBottom_toBottomOf="@+id/tv_duration"
                app:layout_constraintStart_toEndOf="@+id/tv_duration"
                app:layout_constraintTop_toTopOf="@+id/tv_duration" />


        </android.support.constraint.ConstraintLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

提问的理由:

我知道有很多SO问题可以完成同样的任务,但我的要求没什么不同,提出这个问题的理由对我来说没什么用.

期望

最佳答案
将CardView背景设置为app:cardBackgroundColor =“#00ffffff”

转载注明原文:android – 将RecyclerView CardView背景更改为透明 - 代码日志