在自定义对话框上删除黑色背景 [英] 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.
;
AlertDialog代码
public class MyAlertDialog extends AlertDialog {
public MyAlertDialog(Context context)
{
super(context);
}
public MyAlertDialog(Context context, int theme)
{ super(context, theme); }
}
活动代码
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();
}
样式
<?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>
图片资源
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
推荐答案
public MyAlertDialog(
Context context,
int theme
) extends AlertDialog {
super(context, theme);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}
这篇关于在自定义对话框上删除黑色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文