Android TextView 个别文字字体颜色格式

Android TextView 个别文字字体颜色格式 
1.简单的办法,用Html来格式化字符 
Java代码   收藏代码
  1. import android.app.Activity;  
  2. import android.os.Bundle;  
  3. import android.text.Html;  
  4. import android.widget.TextView;  
  5.   
  6. public class AndroidFronColorTest extends Activity {  
  7.     @Override  
  8.     public void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.           
  11.         setContentView(R.layout.main);  
  12.           
  13.         TextView htmlFormateTextView = (TextView)findViewById(R.id.testTextView);  
  14.           
  15.         String source = "这只是一个测试,测试<u>下划线</u>、<i>斜体字</i>、<font color='red'>红色字</font>的格式";  
  16.    
  17.         htmlFormateTextView.setText(Html.fromHtml(source));  
  18.     }  
  19. }  


http://ghostfromheaven.iteye.com/blog/751099  转自

你可能感兴趣的:(Android TextView 个别文字字体颜色格式)