I assume that you are using TextView
to display Chinese words.
If you want any words in TextView to be in bold or italics, that would be easy. Just use
testView.getPaint().setFakeBoldText(true);
to make all the words bold.
For italics use:
testView.getPaint().setTextSkewX(-0.25f);
However, if you want some words to be bold or italics. You can usually set StyleSpan
in a specific range of your Spannable
, but it does not work with the Chinese word.
Therefore, I suggest you create an extends StyleSpan
class
public class ChineseStyleSpan extends StyleSpan{ public ChineseStyleSpan(int src) { super(src); } public ChineseStyleSpan(Parcel src) { super(src); } @Override public void updateDrawState(TextPaint ds) { newApply(ds, this.getStyle()); } @Override public void updateMeasureState(TextPaint paint) { newApply(paint, this.getStyle()); } private static void newApply(Paint paint, int style){ int oldStyle; Typeface old = paint.getTypeface(); if(old == null)oldStyle =0; else oldStyle = old.getStyle(); int want = oldStyle | style; Typeface tf; if(old == null)tf = Typeface.defaultFromStyle(want); else tf = Typeface.create(old, want); int fake = want & ~tf.getStyle(); if ((want & Typeface.BOLD) != 0)paint.setFakeBoldText(true); if ((want & Typeface.ITALIC) != 0)paint.setTextSkewX(-0.25f);
Set this range to your Chinese words, and I should work. Remember that it is installed only in Chinese words. I have not tested it, but I can imagine that a set of fakes on fat English characters would be very ugly.
Yeung source share