Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AlertDialog Android中的新行字符_Android_Android Alertdialog_Unicode Escapes - Fatal编程技术网

AlertDialog Android中的新行字符

AlertDialog Android中的新行字符,android,android-alertdialog,unicode-escapes,Android,Android Alertdialog,Unicode Escapes,我从windows应用程序接收到一个字符串,该字符串如下所示: 一些文本\r\n一些其他文本 当我在警报对话框中显示该字符串时,我会看到以下内容: 一些文本或一些其他文本 相同的字符串正确显示在TextView上,但未显示在AlertDialog中 请告诉我该怎么做 致以最良好的祝愿 编辑 这就是我迄今为止所尝试的: CustomDialog.Builder dialog = new CustomDialog.Builder(this, "", getString(R.string.ok));

我从windows应用程序接收到一个字符串,该字符串如下所示:

一些文本\r\n一些其他文本

当我在警报对话框中显示该字符串时,我会看到以下内容:

一些文本或一些其他文本

相同的字符串正确显示在TextView上,但未显示在AlertDialog中

请告诉我该怎么做

致以最良好的祝愿

编辑 这就是我迄今为止所尝试的:

CustomDialog.Builder dialog = new CustomDialog.Builder(this, "", getString(R.string.ok));
    dialog.contentColor(getResources().getColor(R.color.content_color));
    dialog.titleColor(getResources().getColor(R.color.content_color));
    dialog.positiveColor(getResources().getColor(R.color.cpb_red));
    dialog.content(Message.replace("\r\n", "\n"));
    dialog.build().show();
编辑2: 让我进一步解释一下,我从Windows上的WCF服务接收到一个JSON响应,使用 解析后从JSON接收的文本是

服务器将\r\n关闭以进行维护

我们只是出于测试目的添加了\r\n,但我相信在向Android发送数据时,会有人使用它们。
我尝试过使用replace函数进行替换,但没有成功。

在StringreplaceAll调用中转义反斜杠对我有效

String text = "some text\r\nsome other text";
System.out.println("preprocess text: " + text);
String post = text.replaceAll("\\r\\n", ":");
System.out.println("postprocess text: " + post);
产生:

preprocess text: some text
some other text
postprocess text: some text:some other text

将\r\n替换为\n并转义slash@TimCastelijnsreplace函数并没有替换它们,当您的代码不工作时,我会一直看到相同的结果。你能告诉我们你是怎么尝试的吗that@TimCastelijns请检查我的编辑。我很确定在替换调用中,您还必须避开斜杠。这不起作用,我甚至使用了Log.d和println。我仍然看到我在问题中发布的相同文本。具有讽刺意味的是,同样的文本在iPhone上也可以工作,而不需要替换任何内容:-/