当我定义一个TextView在xml,我如何添加一个新的行?\n似乎不起作用。

<TextView
   android:id="@+id/txtTitlevalue"
   android:text="Line1 -\nLine2"
   android:layout_width="54dip"
   android:layout_height="fill_parent"
   android:textSize="11px" />

当前回答

试试这个:

android:text="Lorem Ipsum \nDolor Ait Amet \nLorem Ipsum"

其他回答

<TextView
   android:id="@+id/txtTitlevalue"
   android:text="Line1: \r\n-Line2\r\n-Line3"
   android:layout_width="54dip"
   android:layout_height="fill_parent"
   android:textSize="11px" />

我认为这行得通。

Programatically: myTV。背景(“我的文本”+“\n”+ mystline);

这解决了我的问题。

stringVar.replaceAll("\\\\n", "\\\n");

RuDrA05的答案很好,当我在eclipse上编辑XML时,它不起作用,但当我用notepad++编辑XML时,它确实起作用。

如果我读取一个用eclipse或notepad++保存的txt文件,也会发生同样的事情

可能和编码有关。

旁注:使用大写文本

android: inputType = textCapCharacters”

或类似的似乎阻止了\n的工作。