Spin 字体高亮 颜色等


Spin 字体高亮 颜色等
 

public class MainAtivity extends Activity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
TextView txtInfo = new TextView(this); 
SpannableStringBuilder ss = null; 
for (int i = 0; i < 2; i++) { 
ss= new SpannableStringBuilder("红色打电话斜体删除线绿色下划线背景"); 
       ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 2, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new URLSpan("tel:4155551212"), 2, 5, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 5, 7, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new StrikethroughSpan(), 7, 10, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new UnderlineSpan(), 10, 16, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new ForegroundColorSpan(Color.GREEN), 10, 15, 
               Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       ss.setSpan(new  BackgroundColorSpan(Color.rgb(124, 156, 215)), 15, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
       txtInfo.append(ss); 
}              
       txtInfo.setMovementMethod(LinkMovementMethod.getInstance()); 
       setContentView(txtInfo); 

} 
} 

 

 

你可能感兴趣的:(android,字体,下划线,textview高亮)