可以通过修改AlertDialog的布局来解决此问题。在AlertDialog.Builder中调用setView方法来设置弹出窗口的布局,然后设置布局中的元素宽度,例如TextView和EditText。
示例代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.your_layout, null);
TextView textView = (TextView) view.findViewById(R.id.your_text_view);
EditText editText = (EditText) view.findViewById(R.id.your_edit_text);
ViewGroup.LayoutParams textLayoutParams = textView.getLayoutParams();
/* 根据需要设置宽度,例如: */
textLayoutParams.width = 600;
textView.setLayoutParams(textLayoutParams);
ViewGroup.LayoutParams editLayoutParams = editText.getLayoutParams();
/* 根据需要设置宽度,例如: */
editLayoutParams.width = 600;
editText.setLayoutParams(editLayoutParams);
builder.setView(view);
AlertDialog dialog = builder.create();
dialog.show();
此代码演示了如何从布局文件中获取TextView和EditText,并设置它们的宽度。可以更改代码中的布局ID和宽度来适应您的需求。
上一篇:AlertDialog不显示文本
下一篇:AlertDialog存在问题。