How to use SpannableString

来源:互联网 发布:ambari源码 编辑:程序博客网 时间:2024/05/16 08:32
 // make the text twice as large
     styledString.setSpan(newRelativeSizeSpan(2f),0,5,0);
      
     // make text bold
     styledString.setSpan(newStyleSpan(Typeface.BOLD),7,11,0);
      
     // underline text
     styledString.setSpan(newUnderlineSpan(),13,23,0);
      
     // make text italic
     styledString.setSpan(newStyleSpan(Typeface.ITALIC),25,31,0);
      
     styledString.setSpan(newStrikethroughSpan(),33,46,0);
      
     // change text color
     styledString.setSpan(newForegroundColorSpan(Color.GREEN),48,55,0);
      
     // highlight text
     styledString.setSpan(newBackgroundColorSpan(Color.CYAN),57,68,0);
      
     // superscript
     styledString.setSpan(newSuperscriptSpan(),72,83,0);
     // make the superscript text smaller
     styledString.setSpan(newRelativeSizeSpan(0.5f),72,83,0);
      
     // subscript
     styledString.setSpan(newSubscriptSpan(),87,96,0);
     // make the subscript text smaller
     styledString.setSpan(newRelativeSizeSpan(0.5f),87,96,0);
      
     // url
     styledString.setSpan(newURLSpan("http://www.google.com"),98,101,0);
      
     // clickable text
     ClickableSpan clickableSpan = newClickableSpan() {
    
   @Override
   publicvoidonClick(View widget) {
    // We display a Toast. You could do anything you want here.
    Toast.makeText(SpanExample.this,"Clicked", Toast.LENGTH_SHORT).show();
     
   }
  };
0 0
原创粉丝点击