全屏AlertDialog更改布局颜色

时间:2012-11-20 14:50:30

标签: java android

我正在使用其他答案的代码:

 AlertDialog.Builder adb = new AlertDialog.Builder(this);
    Dialog d = adb.setView(new View(this)).create();
    // (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    d.show();
    d.getWindow().setAttributes(lp);

我真的觉得用它来制作一个alertDialog全屏幕,但颜色最终是带有白色文字的黑色背景,而不是带有黑色文字的白色背景。我不知道这段代码如何改变颜色。任何人都可以提供一些信息吗?

1 个答案:

答案 0 :(得分:0)

在行中:

Dialog d = adb.setView(new View(this)).create();

您停止新的View,默认为黑色背景。

然后在任何地方使用此视图属性:

lp.copyFrom(d.getWindow().getAttributes());
d.getWindow().setAttributes(lp);

<强>解决方案:

创建新视图后,设置背景:

View view = new View(this);
view.setBackgroundColor(...);
Dialog d = adb.setView(view).create();

问候。