AlertDialog 中的 Android EditText 似乎太宽
下图中的 EditText 似乎太宽了。我假设我以某种方式滥用了 SDK,除非确信,否则我不会寻找一种方法来指定 EditText
两侧的一定数量的边距/填充像素。
这个看起来更合适。
这是我的代码(创建第一个“创建标签”对话框):
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();
抱歉,帖子并感谢任何有用的评论。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己刚刚整理了这个。使用
AlertDialog
实例,您可以指定setView
并传入间距参数。这会起作用。编辑:我知道这个问题很旧,但没有提供解决方案。
Just sorted this myself. Using an instance of
AlertDialog
, you can specifysetView
and pass in spacing parameters. This will work.Edit: I'm aware this question is old, but no solution was provided.
您可以这样做:
此外,
setSingleLine
已被弃用。您应该使用InputStyle
。You can do it like this:
Moreover,
setSingleLine
is deprecated. You should useInputStyle
.将布局 marginleft 和布局 marginright 设置为 5sp。边距设置视图组周围的空间。看看 ViewGroup.MarginLayoutParams
Set the layout marginleft and layout marginright to 5sp. The margin sets the space around the view group. Take a look at ViewGroup.MarginLayoutParams
尝试使用 setPadding 方法。这应该在 EditText 的边缘和对话框的边框之间添加一个间隙。氮
Try setting some padding on your
EditText
using the setPadding method. This should add a gap between the edge of the EditText and the border of the dialog. N