Android 将RecyclerView CardView背景更改为透明
问题简短版本: 我想让我的CardView和RecyclerView背景透明,所以 片段/活动背景应可见 解释: 我有一个带有背景图像的活动A,片段B在其框架布局上被替换,在片段B中,我有recyclerView,现在的问题是我想让每个背景都透明,这样只有CardView才能在活动的实际背景中可见 RecyclerView看起来像这样(这些白色背景应该是透明的): 代码 活动(A)Android 将RecyclerView CardView背景更改为透明,android,android-recyclerview,transparent,android-cardview,cardview,Android,Android Recyclerview,Transparent,Android Cardview,Cardview,问题简短版本: 我想让我的CardView和RecyclerView背景透明,所以 片段/活动背景应可见 解释: 我有一个带有背景图像的活动A,片段B在其框架布局上被替换,在片段B中,我有recyclerView,现在的问题是我想让每个背景都透明,这样只有CardView才能在活动的实际背景中可见 RecyclerView看起来像这样(这些白色背景应该是透明的): 代码 活动(A) 片段(B)RecyclerView 卡片视图/项目布局 提出问题的理由: 我知道要完成同样的任务还有
片段(B)RecyclerView
卡片视图/项目布局
提出问题的理由:
我知道要完成同样的任务还有很多问题,但我的要求有点不同,问这个问题的原因是什么都不适合我
期望值将CardView背景设置为
应用程序:cardBackgroundColor=“#00ffffff”活动中Framelayout的背景色是什么?@Pavya所以你的建议是从我的资源而不是android的资源中分配颜色?我已经尝试过了,但是没有用。app:cardBackgroundColor=“@color/customcolorpransible”
@FrameLayout替换片段有这些背景android:background=“@android:color/transparent”android:backgroundTint=“@android:color/transparent”
粘贴您的活动xml是否尝试在活动xml中使framelayout透明?@ZulqurnainJutt还将recyclerview background设置为#00fffffft,但这也不起作用,很抱歉响应太晚。如果希望显示片段背景,则所有上层都应透明
<?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"/>
<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>
<?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>