gpt4 book ai didi

android - 删除自定义对话框上的黑色背景

转载 作者:IT王子 更新时间:2023-10-29 00:07:31 24 4
gpt4 key购买 nike

我想删除自定义对话框上的黑色背景,如图所示。我确定黑色背景来自对话框,而不是来自应用程序的背景。

custom dialog with black background around it ;

AlertDialog 代码

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

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

Activity 代码

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));
}

关于android - 删除自定义对话框上的黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8117849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com