Question

I have an activity styled as a popup:

[Activity(Theme="@android:style/Theme.Dialog")]
public class GameOverPopup : Activity

But I'm always stuck with a white padding around my controls (ignore the black border, it's not part of the popup):

enter image description here

I've tried setting the padding, margin, etc. to 0dp but always have that extra space.

How can I remove it?

UPDATE:

So I've tried the following according to suggestions:

In Styles.xml:

<style name="PopupDialog" parent="android:style/Theme.Dialog">
   <item name="android:padding">0dp</item>
</style>

And then in my Activity (in the OnCreate Override):

SetTheme(Resource.Style.PopupDialog);

Yet I still have the padding :(

Was it helpful?

Solution 2

Got it!!

Problem is that I set the theme in code on the OnCreate AS WELL as an attribute to the activity. So I remove the code from OnCreate and put the following attribute in my popup Activity class:

[Activity(Theme = "@style/PopupDialog")]
public class GameOverPopup : Activity

And my Styles.xml is:

<style name="PopupDialog" parent="android:style/Theme.Dialog">
  <item name="android:windowBackground">@null</item>
  <item name="android:padding">0dp</item>
</style>

OTHER TIPS

As I recall, the auto-generated activities in Eclipse include the Android activity-wide margins by default. You might check to make sure you have removed these lines in your XML layout if you used the default template.

EDIT, to sum up some comments and avoid creating a discussion: it appears that the problem may be due to the default padding in the dialog box style. Try creating a style with that style as its parent, and manually set the padding/margins as needed: http://developer.android.com/guide/topics/ui/themes.html#DefiningStyles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top