如何删除布局背景

how to remove layout background

我正在尝试从弹出对话框中删除背景,但它在 cardview

后面显示 white color

background = @null is not working

<LinearLayout 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:id="@+id/lnrMstr"
android:orientation="vertical"
android:background="#0D000000">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="@dimen/_5sdp"
        app:cardElevation="@dimen/_5sdp"
        app:cardUseCompatPadding="true"
        android:layout_margin="@dimen/_2sdp"
        android:layout_gravity="center_horizontal">

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

</LinearLayout>

尝试将颜色 #0D000000 编辑为 #00000000

<LinearLayout 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:id="@+id/lnrMstr"
android:orientation="vertical"
android:background="#00000000">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="@dimen/_5sdp"
        app:cardElevation="@dimen/_5sdp"
        app:cardUseCompatPadding="true"
        android:layout_margin="@dimen/_2sdp"
        android:layout_gravity="center_horizontal">
 </android.support.v7.widget.CardView>

</LinearLayout>

您不需要从背景中移除该颜色,只需将对话框 window 背景设置为透明即可。

添加代码:

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

参考:more details