问题描述
我正在尝试使用这种方式获取一个自定义对话框:
this.getWindow().setBackgroundDrawableResource(R.drawable.transparent);
(其中"r.drawable.transparent"是对颜色"#00000000")
的引用奇怪的问题是我无法对话框窗口进行对齐.即使我用:
隐式设置窗口的重力,它始终与左侧对齐this.getWindow().setGravity(Gravity.CENTER);
如果我只是评论设置透明背景的行,则对齐工作正常.
任何帮助将非常感谢!
谢谢.
推荐答案
<resources> <color name="transparent">#00000000</color> </resources>
在.java文件中,添加以下内容:
.setBackgroundColor(getResources().getColor(R.color.transparent));
其他推荐答案
您需要在对话框窗口上设置填充.
问题描述
I'm trying to get a custom dialog with a transparent background doing this way:
this.getWindow().setBackgroundDrawableResource(R.drawable.transparent);
(where "R.drawable.transparent" is a reference to the color "#00000000")
The weird issue on this is that I can't align my dialog window. It's always aligned to the left, even if I implicit set the Gravity of the window using:
this.getWindow().setGravity(Gravity.CENTER);
And if I just comment the line which set the transparent background, the alignment works fine.
Any help would be much appreciated!
Thanks.
推荐答案
In the strings.xml file, add the following:
<resources> <color name="transparent">#00000000</color> </resources>
In the .java file, add the following:
.setBackgroundColor(getResources().getColor(R.color.transparent));
其他推荐答案
You need to set the padding on the dialog window.