Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

   @Override
protectedvoidonCreate(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);
   } 

Solution 2:

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

@OverrideprotectedvoidonStart() {
   super.onStart();
   // In order to not be too narrow, set the window size based on the screen resolution:finalintscreen_width= getResources().getDisplayMetrics().widthPixels;
   finalintnew_window_width= screen_width * 90 / 100; 
   LayoutParamslayout= getWindow().getAttributes();
   layout.width = Math.max(layout.width, new_window_width); 
   getWindow().setAttributes(layout);
}

Solution 3:

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

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

Solution 4:

Solution 5:

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

Post a Comment for "Theme.dialog Creates Too Small Screen"