Code example for SpannableString

Methods: toHtml

0
        assertEquals(Html.toHtml(s), "<p>Hello &lt;&amp;&gt; world</p>\n");
 
        s = new SpannableString("Hello \u03D5 world");
        assertEquals(Html.toHtml(s), "<p>Hello &#981; world</p>\n");
 
        s = new SpannableString("Hello  world");
        assertEquals(Html.toHtml(s), "<p>Hello&nbsp; world</p>\n");
    } 
 
    @SmallTest 
    public void testMarkup() throws Exception { 
        SpannableString s;
 
        s = new SpannableString("Hello bold world");
        s.setSpan(new StyleSpan(Typeface.BOLD), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s), "<p>Hello <b>bold</b> world</p>\n");
 
        s = new SpannableString("Hello italic world");
        s.setSpan(new StyleSpan(Typeface.ITALIC), 6, s.length() - 6,
Stop searching for code, let great code find you!  Add Codota to your java IDE