透明的对话框对准[英] Transparent Dialog Alignment

本文是小编为大家收集整理的关于透明的对话框对准的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试使用这种方式获取一个自定义对话框:

this.getWindow().setBackgroundDrawableResource(R.drawable.transparent);

(其中"r.drawable.transparent"是对颜色"#00000000")

的引用

奇怪的问题是我无法对话框窗口进行对齐.即使我用:

隐式设置窗口的重力,它始终与左侧对齐
this.getWindow().setGravity(Gravity.CENTER);

如果我只是评论设置透明背景的行,则对齐工作正常.

任何帮助将非常感谢!

谢谢.

推荐答案

strings.xml文件中,添加以下内容:

<resources>
<color name="transparent">#00000000</color>
</resources>

在.java文件中,添加以下内容:

.setBackgroundColor(getResources().getColor(R.color.transparent));

其他推荐答案

您需要在对话框窗口上设置填充.

本文地址:https://www.itbaoku.cn/post/102502.html

问题描述

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.