Activity as dialog: Place in top left corner

2019-08-30 07:53发布

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():

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

(This is Mono for Android)

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

Notice the gap between the menu box and the actual edge of the screen. What can I do to remove that gap completly?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-30 08:15

Turns out the problem is rather simple: Theme.Holo.Dialog defines a background that adds a transparent border around the 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.

查看更多
登录 后发表回答