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

时间:2015-09-25 08:39:02

标签: android android-alertdialog

我正在使用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();
    }

3 个答案:

答案 0 :(得分:3)

试试这个,它对我有用

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

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

答案 1 :(得分:0)

此问题的正确答案是

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

对我来说,魅力无比。希望对别人有帮助

答案 2 :(得分:0)

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

 <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);
相关问题