Java 全屏警报对话框更改布局颜色
我在这里使用另一个答案中的代码:Java 全屏警报对话框更改布局颜色,java,android,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
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全屏是很有用的,但是颜色最终是带白色文本的黑色背景,而不是带黑色文本的白色背景。我不知道这个代码是如何改变颜色的。有人能提供一些信息吗?在以下行中:
Dialog d = adb.setView(new View(this)).create();
您可以创建一个新的视图
,默认为黑色背景
然后在任何地方使用此视图属性:
lp.copyFrom(d.getWindow().getAttributes());
d.getWindow().setAttributes(lp);
解决方案:
创建新视图后,设置背景:
View view = new View(this);
view.setBackgroundColor(...);
Dialog d = adb.setView(view).create();
注意。在此代码中,您在何处设置文本的布局或颜色?也许你应该给我们更多的代码?这是我的观点。根本没有改变颜色的代码,但它们确实会改变。我希望可能有人知道一些导致它的小特性。我在这段代码中看到的是:在对话框中创建一个新视图,将其设置到整个对话框中,仅此而已。为什么,judjing根据这个代码,你认为背景应该是白色的,文本应该是黑色的?我所有的其他布局都有白色背景。这是唯一不同的。此外,在xml编辑器中,它也会以黑色文本显示白色!也许在您的其他布局中设置了灯光主题,而在此对话框中默认的主题是黑色?