2012-11-20 51 views
1

我正在使用的代码从另一个答案在这里:全屏AlertDialog改变布局颜色

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

我真的觉得它usefl作出alertDialog全屏,但颜色最终被一个黑色的背景白色文本,而不是带有黑色文本的白色背景。我不知道这段代码如何改变颜色。谁能提供一些信息?

+0

在此代码中,您为文本设置了布局或颜色?也许你应该让我们多一些代码? – jumper0k

+0

这就是我的观点。没有代码可以改变颜色,但它们确实会改变。我希望也许有人知道导致它的一些小特质。 – EGHDK

+0

我在这段代码中看到:在对话框中创建一个新视图,将其设置到整个对话框中,就这些了。为什么,用你认为的这段代码判断,背景应该是白色的,文本应该是黑色的? – jumper0k

回答

0

在行:

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

你ceate新View默认为黑色背景。

然后你可以使用该视图属性无处不在:

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

解决方案:

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

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

问候。