简体   繁体   English

活动作为对话框:放在左上角

[英]Activity as dialog: Place in top left corner

I'm trying to place an Android activity that uses the Holo.Dialog theme in the top left corner of my application by using the following code in OnCreate(): 我试图通过在OnCreate()中使用以下代码,在应用程序的左上角放置一个使用Holo.Dialog主题的Android活动:

var layoutParams = this.Window.Attributes;
layoutParams.Gravity = GravityFlags.Top | GravityFlags.Left;

(This is Mono for Android) (这是Android版Mono)

It kind of works, however there is a tiny gap between the actual corner and the beginning of my dialog, which you can see in the following screen shot: 确实可以,但是实际的转角和对话框的开始之间有微小的差距,您可以在以下屏幕截图中看到:

https://www.dropbox.com/s/cyy9lglq5642nz1/device-2013-05-26-223855.png https://www.dropbox.com/s/cyy9lglq5642nz1/device-2013-05-26-223855.png

Notice the gap between the menu box and the actual edge of the screen. 注意菜单框和屏幕实际边缘之间的间隙。 What can I do to remove that gap completly? 我该怎么做才能彻底消除这一差距?

Turns out the problem is rather simple: Theme.Holo.Dialog defines a background that adds a transparent border around the dialog. 原来问题很简单:Theme.Holo.Dialog定义了一个在对话框周围添加透明边框的背景。 This causes the spacing between the corner and the dialog. 这将导致角和对话框之间的间距。

Creating a custom style fixes it: 创建自定义样式可以解决此问题:

<style name="MyCustomDialog" parent="android:Theme.Holo.Dialog">
    <item name="android:windowBackground">@null</item>
</style>

This overwrites the background and removes the spacing. 这将覆盖背景并删除间距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM