如何在 Android 上获取多行警报标题
有没有办法在 AlertDialog
中获取超过 2 行的警报标题?
我只发现“创建自定义对话框”作为可能的解决方案。
然而,理想情况下,人们可以只设置一个属性 - 但我找不到任何属性。
编辑:
AlertDialog alertDialog = new AlertDialog.Builder(AlertAndCallUtility.this).create();
alertDialog.setTitle(getString(R.string.alert_title));
alertDialog.setMessage(getString(R.string.alert_msg));
alertDialog.setButton(getString(R.string.alert_OK),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
和如上所述的 xml
<string name="alert_OK">OK:</string>
<string name="alert_title">Please correct your input, parameters are missing.</string>
<string name="alert_msg">Please enter them in the EXTRA tab.</string>
,在“..missing”之前插入 \n,只需将其切断,并且只能看到前两行,直到标题的“are”。
Is there a way to get more than the 2 lines for the Alert title in an AlertDialog
?
I only find "creating a custom dialog" as a possible solution.
Ideally however, one could just set an attribute
- but I can't find any.
EDIT:
AlertDialog alertDialog = new AlertDialog.Builder(AlertAndCallUtility.this).create();
alertDialog.setTitle(getString(R.string.alert_title));
alertDialog.setMessage(getString(R.string.alert_msg));
alertDialog.setButton(getString(R.string.alert_OK),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
and xml
<string name="alert_OK">OK:</string>
<string name="alert_title">Please correct your input, parameters are missing.</string>
<string name="alert_msg">Please enter them in the EXTRA tab.</string>
as mentioned, inserting a \n right before "..missing", just cuts it off and one only sees the first two lines until "are" of the title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用AlertDialog.Builder().setCustomTitle():
You need to use AlertDialog.Builder().setCustomTitle():
这是一个不太可能的方案,但是您是否尝试过在标题中使用
\n
来强制换行?This is a long-shot, but have you tried using
\n
in your title for force a newline?