Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove black background on custom dialog

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.

custom dialog with black background around it ;

AlertDialog code

public class MyAlertDialog extends AlertDialog {      public MyAlertDialog(Context context)      {           super(context);      }        public MyAlertDialog(Context context, int theme)      { super(context, theme); } } 

Activity code

public void showMyDialogOK(Context context, String s, DialogInterface.OnClickListener OkListener) {             MyAlertDialog myDialog = new MyAlertDialog(context, R.style.MyDialog2);             myDialog.setTitle(null);      myDialog.setMessage(s);             myDialog.setButton(DialogInterface.BUTTON_POSITIVE ,"Ok", OkListener);     myDialog.show();     } 

Styles

<?xml version="1.0" encoding="utf-8"?>     <resources>         <style name="MyTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">             <item name="android:alertDialogStyle">@style/AlertDialog</item>           </style>              <style name="MyTheme2" parent="@android:style/Theme.Black">             <item name="android:alertDialogStyle">@style/AlertDialog</item>             </style>           <style name="AlertDialog">                     <item name="android:fullDark">@null</item>             <item name="android:fullBright">@null</item>             <item name="android:topDark">@drawable/popup_top_dark</item>             <item name="android:topBright">@null</item>             <item name="android:centerBright">@null</item>             <item name="android:centerDark">@drawable/popup_center_dark</item>             <item name="android:centerMedium">@null</item>             <item name="android:bottomDark">@null</item>             <item name="android:bottomBright">@null</item>             <item name="android:bottomMedium">@drawable/popup_bottom_medium</item>         </style>          <style name="MyDialog2" parent="@android:Theme.Dialog">                     <item name="android:windowBackground">@null</item>                 <item name="android:buttonStyle">@style/CustomButton</item>           </style>              <style name="CustomButton" parent="@android:style/Widget.Button">                     <item name="android:background">@drawable/button_stateful</item>           </style> </resources> 

Image resources

popup_center_dark.9.png

popup_center_dark.9.png

popup_bottom_medium.9.png

popup_bottom_medium.9.png

popup_top_dark.9.png

popup_top_dark.9.png

like image 904
pengwang Avatar asked Nov 14 '11 05:11

pengwang


People also ask

How do I make alert dialog background transparent?

setVerticalScrollBarEnabled(true); wv. setBackgroundColor(Color. TRANSPARENT); wv. setPadding(5, 25, 5, 0); ImageView imgcartl=(ImageView)layout.

How do I change the background color of alert in dialog?

You should use the android:windowBackground theme attribute instead. android:background will change the background color of every View . Actually, both background and windowBackground remove rounded corners from the dialog window. If you want to set a color, you should use colorBackground attribute instead.

How do I turn off custom dialog?

You may call dismiss(); on the dialog. This work for me.


1 Answers

public MyAlertDialog(         Context context,          int theme     ) extends AlertDialog {       super(context, theme);     getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } 
like image 140
dira Avatar answered Sep 24 '22 21:09

dira