Android:更改自定义AlertDialog背景

对话框布局xml:

  //...content...  

点击图钉时,地图叠加中的对话框实现:

 AlertDialog.Builder builder; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.map_kap_dialog, (ViewGroup) mapView.findViewById(R.id.root_view)); //prepare info to show... //info prepared //other preparations stuff builder = new AlertDialog.Builder(context); builder.setView(layout); dialog = builder.create(); dialog.setInverseBackgroundForced(true); dialog.setCanceledOnTouchOutside(true); //show it dialog.show(); 

以及我在测试时看到的内容:

在此处输入图像描述

所以我希望对话框周围的浅灰色背景(方形白色空间周围)变为白色,所以看起来不会那么难看。 谁能帮我?

我有同样的问题,我设法使用这样的自定义对话框修复它:

 public class CustomDialog extends Dialog { public CustomDialog(Context context, View view) { super(context); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(view); getWindow().getDecorView().setBackgroundResource(android.R.color.transparent); } } 

将你的视图设置为构建器会在上下创建这条灰色线条,而不是你可以将ViewView设置为你的dialog.like dialog.setView(layout,0,0,0,0);它会将你的布局绑定到整个对话框。

另一个选择是从你的布局中删除android:background="@android:color/white" 。 然后警报对话框将统一显示其默认的浅灰色背景。 (因为你强迫对暗主题进行反转)至少看起来不错,值得麻烦。 只是我的两分钱。