Home » Android » android – Size of Alert Dialog or Custom Alert Dialog

android – Size of Alert Dialog or Custom Alert Dialog

Posted by: admin June 15, 2020 Leave a comment


I am creating my application for all tablets of 10.1 and now i am trying this on samsung galaxy tab.
I have done all the parts of that but alert dialog is too small regarding tablet size.
I have also created custom alert dialog but it does not look good.
So tell me can i change the size of default alert dialog if yes then how.


how to create custom alert dialog that looks like default alert dialog.


How to&Answers:

Please Refer this one

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window’s top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to FILL_PARENT.

Demo code:

AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;

Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)

It would be better to do this by extending Theme.Dialog, then you wouldn’t have to play a guessing game about when to call setAttributes. (Although it’s a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )