如何删除布局背景

时间:2018-08-20 12:47:12

标签: android android-layout android-alertdialog android-cardview

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

后面显示了white color
  

background = @null不起作用

<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>

2 个答案:

答案 0 :(得分:2)

您无需从背景中删除该颜色,只需将对话框窗口背景设置为透明即可。

添加代码:

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

参考:more details

答案 1 :(得分:0)

通过将颜色#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>