方法一 用Html格式化字符设置
TextView htmlFormateTextView = (TextView)findViewById(R.id.txtTextView);
String source = "这是一个测试,测试<u>下划线</u>、<i>斜体字</i>、<font color='red'>红色字</font>的格式";
htmlFormateTextView.setText(Html.fromHtml(source));
方法二 利用Spannable设置
EditText et = (EditText) findViewById(R.id.txtTextView);
Spannable sp = (Spannable) et.getText();
sp.setSpan(new BackgroundColorSpan(Color.RED), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 6, 11, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
扩展知识Spannable