I'm looking for a way to resize (so it doesn't touch the edges) an EditText
inside of an AlertDialog
.
My sample 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:
Add your EditText
inside a LinearLayout
and set margins to that layout.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With