简体   繁体   中英

Android show HTML on TextView method fromHtml

I am trying to display HTML in my textview. I found this page and it says to use .fromHtml. I get an error when I try to use it

TextView tvAbout = (TextView) window.findViewById(R.id.tvAbout);
Spanned about_text = Html.fromHtml(R.string.about_text);
tvAbout.setText(about_text);

Eclipse suggests I use toHtml . When I do that it then suggest I use fromHtml . Suggestions?

Try this..

Use getString before getting from string.xml

    Spanned about_text = Html.fromHtml(getString(R.string.about_text));

The Html.fromHtml expects a string parameter, while the parameter you have provided "R.string.about_text" is an integer ID. Thats the reason for your error.

So follow Hariharan's answer to correct it to get the text from that ID.

getString(R.string.about_text)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM