gpt4 book ai didi

android - 在 edittext 中克服\n

转载 作者:行者123 更新时间:2023-11-30 01:38:14 25 4
gpt4 key购买 nike

我正在编辑文本,通过输入一些文本然后转到软键盘上的 enter 键它将再次转到下一行按 enter 它将转到第三行最后编辑文本的结果文本应该由三行空格。

如何在一行中得到结果?

如有任何帮助,我们将不胜感激。

最佳答案

在 xml 文件中制作 android:singleLine="true" 是正确的方法。

  <EditText
android:id="@+id/editText1_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ems="10" >

但是,如果你想在 edittext 中输入多行并在一行中打印(显示),请按以下操作(这不是首选方式,但你需要这样做如下所示)

String editTextVal =(EditText)findViewById(R.id.editText1_1)).getText().toString();
Log.d("in single Line", Html.fromHtml(editTextVal.replace("\n", " ")).toString());

试试这个。

注意:从 xml 中删除多行的 android:singleLine="true"

关于android - 在 edittext 中克服\n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852942/

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