It seems like the EditText in the image below is too wide. I assume that I have misused the SDK in some way and until convinced otherwise I am not looking for a way to specify some number of margin/padding pixels on the sides of the EditText
.
This one looks more appropriate.
Here's my code (that creates the first, 'Create Tag', dialog):
final Dao<Tag, Integer> tagDao = getHelper().getTagDao();
final EditText input = new EditText(this);
input.setSingleLine(true);
input.setHint(R.string.create_tag_dialog_hint);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(input);
builder.setTitle(getString(R.string.create_tag_dialog_title));
builder.setPositiveButton(
getString(R.string.create_tag_dialog_positive),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString().trim();
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
Tag tag = new Tag(value);
try {
tagDao.create(tag);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
builder.setNegativeButton(
getString(R.string.create_tag_dialog_negative), null);
builder.show();
Sorry for the length of the post and thanks for any helpful comments.
show(); alertDialog. getWindow(). setLayout(600, 400); //Controlling width and height. Or you can do it in my way.
Builder adb = new AlertDialog. Builder(this); Dialog d = adb. setView(new View(this)). create(); // (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
A simple dialog containing an DatePicker . This class was deprecated in API level 26.
Just sorted this myself. Using an instance of AlertDialog
, you can specify setView
and pass in spacing parameters. This will work.
final EditText input = new EditText(this);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setView(input, 10, 0, 10, 0); // 10 spacing, left and right
alertDialog.setButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Clicked
}
});
alertDialog.show();
Edit: I'm aware this question is old, but no solution was provided.
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