【问题标题】:How do i start a new line in String? [duplicate]如何在字符串中开始新行? [复制]
【发布时间】:2012-07-25 04:27:26
【问题描述】:

可能重复:
how do i create a multiline string in EditText?

我想在多行 EditText 中显示一个字符串。目前,字符串显示为....

Receive: 0 coin(s) Total
             Cost: $100

我希望它显示为...

Receive: 0 coin(s) 
Total Cost: $10

这是我的代码,我尝试使用“\n”,但无济于事......

result.setText("Receive:"+ " "+ df.format(rawounces)+"coin(s)" + "\n" 
     + "Total Cost:$" + df.format(transactionandpremium*rawounces));

提前谢谢你。

【问题讨论】:

  • 继续删除其中任何一个。不要浪费资源。
  • 就在 20 分钟前,同一用户提出了相同的问题。你可以编辑同样的问题。为什么你又用不同的标题问了... [应该关闭一个]

标签: android string android-edittext settext


【解决方案1】:

您可以使用 Html 属性将文本设置为 ::

<EditText
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />

String str="Receive: 0 coin(s) <br> Total Cost: $10";
editText.setText(Html.formHtml(str));  

【讨论】:

    猜你喜欢
    • 2013-07-30
    • 2017-12-08
    • 2017-01-21
    • 1970-01-01
    • 2021-01-19
    • 2013-05-18
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    相关资源
    最近更新 更多