0

I'm trying to create an AlertDialog with an EditText which height matches the whole dialog window. is it possible to do that without create a custom layout?

what im trying is:

final EditText inputImports = new EditText(getContext());
                    inputImports.setMaxLines(500);
                    inputImports.setInputType(TYPE_TEXT_FLAG_NO_SUGGESTIONS);

                    AlertDialog alert = new AlertDialog.Builder(this.getContext()).setTitle(R.string.importar).setMessage(R.string.importCustomList).setView(inputImports).setCancelable(false).setNegativeButton(R.string.cancel, null).create();
                    alert.setOnShowListener(dialog12 -> {
                        ((AlertDialog) dialog12).getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
                        inputImports.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                        inputImports.requestLayout()
                    });
                    alert.show();

this makes the dialog window matches the phone height but the edittext still appears as a singleline edittext

enter image description here

i would like the edittext take as much as possible of the window space

==============================UPDATE==================================

another thing is that when the keyboard is shown the action button doesnt add a new line it is just some sort of OK button.

i want a very simple alertdialog with multline edittext... why so difficult

enter image description here

1 Answer 1

0

Add LayoutParams for the Edittext

final EditText inputImports = new EditText(getContext());
inputImports.setMaxLines(500);
inputImports.setInputType(TYPE_TEXT_FLAG_NO_SUGGESTIONS);
inputImports.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

Edit

replace

   inputImports.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;

with

   inputImports.getLayoutParams().height =  ((AlertDialog) dialog12).getWindow().getDecorView().getHeight();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.