TEXTview Loading HTML

Source: Internet
Author: User
Tags sqlite database

  1. public class Mainactivity extends Activity {
  2. @Override
  3. protected void OnCreate (Bundle savedinstancestate) {
  4. Super.oncreate (savedinstancestate);
  5. struct ();
  6. Setcontentview (R.layout.activity_main);
  7. TextView TV = (TextView) Findviewbyid (r.id.txt);
  8. String html = "
  9.                 +  " span class= "tag" ><p>< a href=\ "http://www.dreamdu.com/xhtml/\" > Hyperlink HTML Get started </a> learn Html! </p><p ><font color=\ "# Aabb00\ "> color 1"   
  10.                  +  "</p><p><font  color=\ "#00bbaa \" > color 2</ p><p ><font color=\ "#aabb00 \" > color 1 "  
  11.                 +  " span class= "tag" ></p>< p><font color=\ "#00bbaa \" > color 2</p< span class= "tag" >><p>< font color=\ "#aabb00 \" > color 1 "   
  12.                  +  "</p><p><font  color=\ "#00bbaa \" > color 2</ p><p ><font color=\ "#aabb00 \" > color 1 "  
  13. + "</P><p><font color=\" #00bbaa \ "> Color 2</p ><p><font color=\ "#aabb00 \"> Color 1 "
  14. + "</P><P><FontColor=\ "#00bbaa \"> Color 2</p>< h1> title 1</h1 ><h3> Title 2 </h3>< h6> title 3</h6 ><p> greater than > Less than <</p> <p> "&NBSP;&NBSP;
  15. + "Below is the network picture </P><img src=\" http://avatar.csdn.net/0/3/8/2_zhang957411207.jpg\ "  /></body></html> ";
  16. Tv.setmovementmethod (Scrollingmovementmethod.getinstance ());//Set scrollable
  17. Tv.setmovementmethod (Linkmovementmethod.getinstance ());//Set hyperlinks to open web pages
  18. Tv.settext (html.fromhtml (Html, imggetter, null));
  19. }
  20. @Override
  21. public boolean Oncreateoptionsmenu (Menu menu) {
  22. Inflate the menu; This adds items to the action bar if it is present.
  23. Getmenuinflater (). Inflate (R.menu.activity_main, menu);
  24. return true;
  25. }
  26. The resource inside this is the URL contained in the first parameter of the fromhtml function.
  27. Imagegetter imggetter = new Html.imagegetter () {
  28. Public drawable getdrawable (String source) {
  29. LOG.I ("RG", "Source---?>>>" + source);
  30. drawable drawable = null;
  31. URL url;
  32. try {
  33. url = new URL (source);
  34. LOG.I ("RG", "url---?>>>" + URL);
  35. drawable = Drawable.createfromstream (Url.openstream (), ""); Get Network images
  36. } catch (Exception e) {
  37. E.printstacktrace ();
  38. return null;
  39. }
  40. Drawable.setbounds (0, 0, drawable.getintrinsicwidth (),
  41. Drawable.getintrinsicheight ());
  42. LOG.I ("RG", "url---?>>>" + URL);
  43. return drawable;
  44. }
  45. };
  46. public static void struct () {
  47. Strictmode.setthreadpolicy (New StrictMode.ThreadPolicy.Builder ()
  48. . Detectdiskreads (). Detectdiskwrites (). Detectnetwork ()//or
  49. . Detectall ()
  50. For
  51. All
  52. Detectable
  53. Problems
  54. . Penaltylog (). build ());
  55. Strictmode.setvmpolicy (New StrictMode.VmPolicy.Builder ()
  56. . Detectleakedsqlliteobjects ()//probing SQLite database operations
  57. . Penaltylog ()//Print Logcat
  58. . Penaltydeath (). build ());
  59. }
  60. }

TEXTview Loading HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.