JBernhardt
JBernhardt

Reputation: 414

Narrow Dialog when starting new Activity in "Theme.Holo.DialogWhenLarge" mode

I feel that I have tried anything to get my dialog fill about 75% (width) of the screen, when it starts. It was always looking great, but since I upgraded to Android 4.4 I cannot get my dialogs to look "normal" but instead they are very small.

When I open a dialog I use the Theme.Holo.DialogWhenLarge as the theme for an activity. All my dialogs are started as activities. I want them to be fullscreen on mobile devices and a dialog (popup) on tablets.

I tried the tips from the following post, but none seem to work:

This issue is driving me nuts... Any advice?

Upvotes: 2

Views: 435

Answers (1)

JBernhardt
JBernhardt

Reputation: 414

I don't know what's wrong with me... ;-) It looks like that as soon as I post a question, I find a working solution:

@Override
protected void onStart() {
   super.onStart();
   // In order to not be too narrow, set the window size based on the screen resolution:
   final int screen_width = getResources().getDisplayMetrics().widthPixels;
   final int new_window_width = screen_width * 75 / 100; 
   LayoutParams layout = getWindow().getAttributes();
   layout.width = Math.max(layout.width, new_window_width); 
   getWindow().setAttributes(layout);
}

I'm still not 100% happy with my solution, because I would like to avoid custom code to get the right screen size, but I guess I do have to work more on my layout. But for now, this solution is working for me.

Upvotes: 3

Related Questions