{"id":8,"date":"2012-02-08T16:50:28","date_gmt":"2012-02-08T07:50:28","guid":{"rendered":"http:\/\/adreamer.godohosting.com\/en\/?p=8"},"modified":"2012-02-08T17:12:15","modified_gmt":"2012-02-08T08:12:15","slug":"using-html-format-in-textview","status":"publish","type":"post","link":"http:\/\/milkdrops.net\/en\/archives\/8","title":{"rendered":"Using HTML format in TextView"},"content":{"rendered":"<p>In Android, HTML formatting is possible by using <a href=\"http:\/\/developer.android.com\/reference\/android\/text\/Html.html#fromHtml(java.lang.String)\" target=\"_blank\">Html.fromHtml()<\/a> in TextView.<\/p>\n<pre lang=\"java\">\r\nTextView tv = (TextView)findViewById(R.id.text);\r\ntv.setText(Html.fromHtml(\"Text with <br><font color=\\'#ff0000\\'>Color<\/font> and <b>Bold<\/b>\"));\r\n<\/pre>\n<p>To use a string from a resource, the string have to be formatted this way:<\/p>\n<p>[strings.xml]<\/p>\n<pre lang=\"xml\">\r\n<string name=\"html_string\">Text with &lt;br&gt;&lt;font color=\\'#898f97\\'&gt;Color&lt;\/font&gt; and &lt;b&gt;Bold&lt;\/b&gt;<\/string>\r\n<\/pre>\n<p>[TestActivity.java]<\/p>\n<pre lang=\"java\">\r\nTextView tv = (TextView)findViewById(R.id.text);\r\ntv.setText(Html.fromHtml(getResources().getString(R.string.html_string)));\r\n<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/adreamer.godohosting.com\/en\/wp-content\/uploads\/2012\/02\/html.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/adreamer.godohosting.com\/en\/wp-content\/uploads\/2012\/02\/html.jpg?resize=474%2C221\" alt=\"\" title=\"HTML format TextView\" width=\"474\" height=\"221\" class=\"alignnone size-full wp-image-21\" srcset=\"https:\/\/i0.wp.com\/milkdrops.net\/en\/wp-content\/uploads\/2012\/02\/html.jpg?w=487 487w, https:\/\/i0.wp.com\/milkdrops.net\/en\/wp-content\/uploads\/2012\/02\/html.jpg?resize=300%2C139 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Android, HTML formatting is possible by using Html.fromHtml() in TextView. TextView tv = (TextView)findViewById(R.id.text); tv.setText(Html.fromHtml(&#8220;Text with Color and Bold&#8221;)); To use a string from a resource, the string have to be formatted this way: [strings.xml] Text with &lt;br&gt;&lt;font color=\\&#8217;#898f97\\&#8217;&gt;Color&lt;\/font&gt; and &lt;b&gt;Bold&lt;\/b&gt; [TestActivity.java] TextView tv = (TextView)findViewById(R.id.text); tv.setText(Html.fromHtml(getResources().getString(R.string.html_string)));<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,3],"tags":[5,10,11],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-android","category-devel","tag-android-2","tag-html-tag","tag-textview"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":17,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":24,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/8\/revisions\/24"}],"wp:attachment":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}