SetText to a TextView
题
I want to set text for a textView by code. My text is something like this :" aaaa \n bbb\n ccc" and if I use setText() method on screen I got exact in this format, and not like this :
"aaaa
bbb
ccc".
If I put in xml android:text="aaaa \n bbb\n ccc" it works fine. I need to set this by code,and not from xml file. How can I do this?
解决方案
Simply use the newline character "\n", like this:
myTextView.setText("aaaa\nbbb\nccc");
That will output:
aaaa
bbb
ccc
其他提示
Use HTML tags:
myTv.setText(Html.fromHtml("<p>aaaa<br/>bbbb<br/>cccc</p>"));
Try like this:
setText("aaaa\nbbb\nccc");
不隶属于 StackOverflow