如何从对话框中删除阴影? android

How to remove shadow from dialog? android

我正在使用 AppCompatDialog 构建对话框界面。

我的目标是在对话视图显示时移除它周围的阴影?

这里是代码示例:

private void showWrongLoginPassDialog(String message){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.ad_login_error_title));
        builder.setMessage(message);
        builder.setPositiveButton(getString(R.string.ad_login_error_positive),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        builder.show();
    }

试试这个,对我有用

dialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);

给你:builder.show().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND‌​);

这道题的正确答案是

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

对我来说就像一个魅力。希望对某人有所帮助

一种可能的解决方案是为您的对话框使用自定义主题。这个自定义主题对我有用。

 <style name="MenuDialog" parent="Theme.AppCompat.Light.Dialog">
    <!--This attribute removes the shadow-->
    <item name="android:background">@android:color/transparent</item>
    <!--This attribute updates the background color of the window-->
    <item name="android:windowBackground">@android:color/white</item>
    <!--Optional: This attribute makes the dialog window non-floating-->
    <item name="android:windowIsFloating">false</item>
</style>

现在,按照以下方式使用主题

 AlertDialog alertDialog = new AlertDialog.Builder(this, R.style.MenuDialog);