问题描述
我试图得到一个自定义对话框具有透明背景做这样的:
I'm trying to get a custom dialog with a transparent background doing this way:
this.getWindow().setBackgroundDrawableResource(R.drawable.transparent);
(其中R.drawable.transparent是参考的颜色#00000000)
(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.
任何帮助将是非常美联社preciated!
Any help would be much appreciated!
感谢。
推荐答案
在的strings.xml文件,添加以下内容:
In the strings.xml file, add the following:
<resources>
<color name="transparent">#00000000</color>
</resources>
在.java文件,添加以下内容:
In the .java file, add the following:
.setBackgroundColor(getResources().getColor(R.color.transparent));
这篇关于透明的对话路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!