Android 调整AlertDialog内EditText的大小
我正在寻找一种方法来调整Android 调整AlertDialog内EditText的大小,android,android-layout,Android,Android Layout,我正在寻找一种方法来调整AlertDialog内部编辑文本的大小(使其不接触边缘) 我的示例代码 我尝试过这里提供的解决方案,但没有成功: 在线性布局中添加您的编辑文本,并设置该布局的边距 AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Test"); LinearLayout layout = new LinearLayout(this); layout.setOrientatio
AlertDialog
内部编辑文本的大小(使其不接触边缘)
我的示例代码
我尝试过这里提供的解决方案,但没有成功:
在线性布局中添加您的编辑文本
,并设置该布局的边距
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Test");
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 30, 0);
EditText textBox = new EditText(myActivity.this);
layout.addView(textBox, params);
alert.setView(layout);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.show();
感谢您抽出时间,这有助于将正确的部分放在正确的位置。对我来说,这使editText更好看->params.setMargins(55,0,55,0);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Test");
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 30, 0);
EditText textBox = new EditText(myActivity.this);
layout.addView(textBox, params);
alert.setView(layout);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.show();