gpt4 book ai didi

java - 如何防止文本在警告对话框中换行?

转载 作者:行者123 更新时间:2023-11-29 21:09:27 24 4
gpt4 key购买 nike

我正在展示一个非常简单的 AlertDialog 使用这个小代码 fragment :

AlertDialog.Builder bldBuilder = new AlertDialog.Builder(WarningActivity.this);
bldBuilder.setMessage(strTrace).setTitle(strTrace.split("\n")[0]);
AlertDialog dlgTrace = bldBuilder.create();
dlgTrace.show();

我的对话框的内容是堆栈跟踪,因此行可能会很长。我想要防止在默认警报对话框中换行,但我似乎无法弄清楚如何。我一直在努力挖掘这个答案,但我一直无法理解如何去做。

最佳答案

您有 2 个可能的选择:第一个是创建您自己的布局。其次是修改默认的 AlertDialog 布局的 textview

//after creating the dialog, get the textview
TextView textView = (TextView) dlgTrace.findViewById(android.R.id.message);

//then set single line to false
textView.setSingleLine(false);

关于java - 如何防止文本在警告对话框中换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23433779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com