Remove black background on custom dialog

前端 未结 13 2212
清歌不尽
清歌不尽 2021-01-30 20:54

I want to remove the black background on custom dialog as shown in the picture. I\'m sure the black background was from the dialog, not from app\'s background.

相关标签:
13条回答
  • 2021-01-30 21:03

    you can create xml layout like following and set that layout on dialog(dialog.xml) :

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android" style="@style/white_background_bl_aatharv">
    
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true" android:id="@+id/instructions_view">
    
            <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:textColor="#FFFFFF"
                android:text="text here " />
        </LinearLayout>
    </ScrollView>
    

    here is the code to set layout on alert dialog :

    AlertDialog alert = cndtnsbuilder.create();
    alert.setView(LayoutInflater.from(
    currentactivity.this).inflate(
    R.layout.dialog, null));
    alert.show();
    
    0 讨论(0)
  • 2021-01-30 21:03

    To remove the background color, on layout, you just need to set the background to @null

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@null">
    
    0 讨论(0)
  • 2021-01-30 21:05
     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    
    0 讨论(0)
  • 2021-01-30 21:14

    Following method worked for me:

    getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    
    0 讨论(0)
  • 2021-01-30 21:14

    //code style in style.xml :

    <style name="translucentDialog" parent="android:Theme.Holo.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>
    

    // in activity :set style to dialog :

       Dialog dialogconf = new Dialog(TreeAct.this, R.style.translucentDialog);
                dialogconf.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                       dialogconf.setContentView(R.layout.dialog_layout);
    
    0 讨论(0)
  • 2021-01-30 21:15

    Just change Dialog parent them.

    With black backround

    <style name="MyDialog2" parent="@android:Theme.Dialog">        
    

    Without black background

    <style name="MyDialog2" parent="@android:style/Theme.DeviceDefault.Light.Dialog">
    
    0 讨论(0)
提交回复
热议问题