OkyDokyman
OkyDokyman

Reputation: 3876

Theme.Dialog creates too small screen

I have an activity with ListView that has:

android:theme="@android:style/Theme.Dialog"

in Manifest. When I open it and when it has only one line in ListView, the window that opens is very small. How do I make the window take the whole screen?

Upvotes: 4

Views: 4664

Answers (6)

PravinCG
PravinCG

Reputation: 7708

Use this in your onCreate method of the Activity to make it full screen.

   @Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.myxml);

    LayoutParams params = getWindow().getAttributes(); 
            params.height = LayoutParams.MATCH_PARENT;
            params.width  = LayoutParams.MATCH_PARENT;
           getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
   } 

Upvotes: 7

user458577
user458577

Reputation:

Yeezz ! I figured it out ! The problem is that the margin sizes are not calculated in the window widht. So If you set the layout margin to 0 and move that part to the padding of the layout the problem will be solved.

Upvotes: 0

Kaptkaos
Kaptkaos

Reputation: 333

Just a small update. Used MATCH_PARENT instead of the deprecated FILL_PARENT. PravinCG's answer worked great for me.

Upvotes: 0

ahcox
ahcox

Reputation: 9970

I have found that setting the window size does work, but you have to do it a bit later. In this example the window width is set to 90% of the display width, and it is done in onStart() rather than onCreate():

@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 * 90 / 100; 
   LayoutParams layout = getWindow().getAttributes();
   layout.width = Math.max(layout.width, new_window_width); 
   getWindow().setAttributes(layout);
}

Upvotes: 3

nawab
nawab

Reputation: 352

Use the suggested code before setcontentview() call. It will work.

Upvotes: 0

Squonk
Squonk

Reputation: 48871

Similar to the answer from PravinCG but it can be done with one line in onCreate()...

getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

Upvotes: 1

Related Questions