调整大小的EditText一个AlertDialog内 [英] Resizing EditText inside of an AlertDialog
本文介绍了调整大小的EditText一个AlertDialog内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方式来调整(因此不会触及边缘),一个EditText的AlertDialog内。
I'm looking for a way to resize (so it doesn't touch the edges) an EditText inside of an AlertDialog.
的我的示例code 的
AlertDialog.Builder alert = new AlertDialog.Builder(myActivity.this);
alert.setTitle("Test");
EditText textBox = new EditText(myActivity.this);
alert.setView(textBox);
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();
我试过没有成功在这里提供的解决方案:
I've tried solutions provided here with no success:
- An Answer
- Another Answer
推荐答案
添加您的EditText一个的LinearLayout内,设置页边距到布局。见下图:
add your edittext inside a linearlayout and set margins to that layout. see below:
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.FILL_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一个AlertDialog内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文