Android developers SpannableString development explain

Foreword

  SpannableString, google is to provide functional classes used to handle rich text Support change the effect of a lot of text content. In addition, it is also the key to achieving rich text editor Android.

 

 

Text color

The following code snippet of text turns red

String content ="这个是红色文字的Demo";
SpannableString spannableString = new SpannableString(content);
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFF0C00")), 3, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(spannableString);

Renderings:

The key line of code is setSpan method, this method of treatment will be used until later in the text.

Text background color

Guess you like

Origin www.cnblogs.com/guanxinjing/p/11227711.html