I have to display some long text on a TextView, i tried to put it on strings.xml
vari开发者_StackOverflowable but had that problem Apostrophe not preceded by \
. I used Java code to set the TextView but all the text must be on one line, and i want that the compiler detects return to line.
My question what is the best approach to make that ? Thanks for helping.
Use mTextSample.setText(Html.fromHtml(text));
Where you can show anything in your TextView using Html.fromHtml().
Example (Some uses):
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
.
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
And some uses :
Android Html.fromHtml takes too long
Display HTML Formatted String
Happy coding :)
You should add it to the strings.xml and add escape characters for all 'sensitive' characters you may use, such as apostrophe. For example
<string name="test">It\'s me</string>
Hope this helps!
If you are having long text to display in text view then should try to set pro grammatically like String text = "Your Text goes here, what ever you want to display";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(text);
Don't forget to put your text view under a scroll view in your layout for better User Expierence.
精彩评论