How to set BOLD,ITALIC & UNDERLINE properties to dynamic textview in Android

Below is the code sample for setting BOLD,ITALIC & UNDERLINE properties to the TextView which is dynamically created and so is the its content. We use "SpannableString" to serve this purpose.

TextView textView=(TextView)findViewById(;

SpannableString spannableString=new SpannableString("Hello String"/*YOUR STRING*/);
/*Set your desired span...*/
new StyleSpan(*OBJECT*/
          , 0/*STARTING POSITION*/
          , spannableString.length()/*ENDING POSITION*/
          , 0/*FLAGS*/);
/*---  Object can be any of the following  ---
new StyleSpan(;
new StyleSpan(;
new StyleSpan(;
new UnderlineSpan();
/*   Set spanned string to views(TextView/Button..) just like
 *   any other string

Happy coding:-)


  1. Note that this only works for system fonts. As I learned the hard way. ;)