我正在尝试创建一个AlertDialog,其高度与整个对话框窗口的高度匹配。是否可以在不创建自定义布局的情况下做到这一点?
我正在尝试什么:
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();
这使对话框窗口与电话高度匹配,但edittext仍显示为单行edittext
我希望edittext占用尽可能多的窗口空间
==============================更新================== =================
另一件事是,显示键盘时,操作按钮未添加新行,而只是某种确定按钮。
我想要一个非常简单的带有多行文本编辑文本的Alertdialog ...为什么这么难
为Edittext添加LayoutParams
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));
编辑
替换
inputImports.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
with
inputImports.getLayoutParams().height = ((AlertDialog) dialog12).getWindow().getDecorView().getHeight();