2010-06-30 232 views

回答

6
private Handler mHandler = new Handler() { 
    void handleMessage(Message msg) { 
      switch(msg.what) { 
       case UPDATE_TEXT_VIEW: 
        tv.setText(msg.obj); // set text with Message data 
        break; 
      } 
    } 
} 

Thread t = new Thread(new Runnable() { 
    // use handler to send message to run on UI thread. 
    mHandler.sendMessage(mHandler.obtainMessage(UPDATE_TEXT_VIEW, Html.fromHtml(text)); 
}); 
t.start(); 
+0

很快!谢谢 – OkyDokyman 2010-06-30 23:18:43

3

如果您不需要解析长或复杂的HTML,的Spannable手动排版比使用Html.fromHtml()快得多。以下样品来自Set color of TextView span in Android

TextView TV = (TextView)findViewById(R.id.mytextview01); 
Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers"); 
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
TV.setText(wordtoSpan); 
相关问题