How To Resize An Alertdialog.builder?
I'd like to resize my AlertDialog.Builder but I didn't find any resolution on this website, I tried everything I saw on questions like this one but seems older than I'm looking for
Solution 1:
You should use custom dialog layout, check documentation.
Actually, you can resize dialog by getDialog().getWindow().setLayout(width, height);
just call it onResume (not onCreateView).
Your view must be nested inside of a ScrollView, check post.
Reading huge amount of text in a Dialog can be annoying, it's better to use all pixels you have, consider simple Activity/Fragment.
Solution 2:
If you're using an AlertDialog within a DialogFragment, with the AppCompat support library 23.2.1 or above, you must put the resize code in DialogFragment.onStart()
, otherwise it will not work. Something like this:
@OverridepublicvoidonStart() {
super.onStart();
// Method 1
alertDialog.getWindow().getAttributes().width = 400; // pixels
alertDialog.getWindow().getAttributes().height = 500; // pixels// Re-apply the modified attributes
alertDialog.getWindow().setAttributes(
alertDialog.getWindow().getAttributes());
// Method 2 (alternative)
alertDialog.getWindow().setLayout(400, 500); // size in pixels
}
More info:
Post a Comment for "How To Resize An Alertdialog.builder?"