Skip to content Skip to sidebar Skip to footer

How To Set Transparent Background As A Custom Dialog Box In Android

I need to make my custom dialog box as a transparent. Sample Code : Dialog dialog; @Override protected Dialog onCreateDialog(int id) { switch(id) { case 1:

Solution 1:

Use dialog instead of AlertDialog

finalDialogdialog=newDialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.splash);
dialog.show();

Solution 2:

If you are on API >= 11, you can try to set a theme to your Dialog like that :

new AlertDialog.Builder(mContext , android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

Or you can try to set the background transparent :

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

Solution 3:

Just create a style and apply that to your dialog

<stylename="myDialogTheme"parent="@android:style/Theme.Dialog"><itemname="android:windowBackground">@color/Transparent</item><itemname="android:windowIsFloating">false</item><itemname="android:windowNoTitle">true</item></style>

Then, create your Dialog by using this theme;

DialogmyDialog=newDialog(this,R.style.myDialogTheme) {
        @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.about_page);
        }
    };

Hope this will help you to achieve your goal.

Solution 4:

Try this,

layout.setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));

add the code above after this line.

Viewlayout= inflater.inflate( R.layout.about_page, ( ViewGroup ) findViewById( R.id.about_Root ) );

Solution 5:

Use dialog.getWindow().setBackgroundDrawable(null) to remove the default background.

Here is the doc for reference:

/*** Set the background to a given Drawable, or remove the background. If the
   * background has padding, this View's padding is set to the background's
   * padding. However, when a background is removed, this View's padding isn't
   * touched. If setting the padding is desired, please use
   * {@link #setPadding(int, int, int, int)}.
   *
   * @param d The Drawable to use as the background, or null to remove the
   *        background
   */

Post a Comment for "How To Set Transparent Background As A Custom Dialog Box In Android"