如何在 Android 上获取多行警报标题

发布于 2024-12-09 01:15:35 字数 951 浏览 0 评论 0原文

有没有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千笙结 2024-12-16 01:15:35

您需要使用AlertDialog.Builder().setCustomTitle():

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
TextView textView = new TextView(context);
textView.setText("your very long title here");
dialogBuilder.setCustomTitle(textView);

You need to use AlertDialog.Builder().setCustomTitle():

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
TextView textView = new TextView(context);
textView.setText("your very long title here");
dialogBuilder.setCustomTitle(textView);
分开我的手 2024-12-16 01:15:35

这是一个不太可能的方案,但是您是否尝试过在标题中使用 \n 来强制换行?

This is a long-shot, but have you tried using \n in your title for force a newline?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文