Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 调整AlertDialog内EditText的大小_Android_Android Layout - Fatal编程技术网

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();