Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume you are using <code>TextView</code> to show Chinese words.</p> <p>If you want the whatever words in TextView to be bold or italic, it would be easy. Just use</p> <pre><code>testView.getPaint().setFakeBoldText(true); </code></pre> <p>to make all words bold. </p> <p>For italic, use:</p> <pre><code>testView.getPaint().setTextSkewX(-0.25f); </code></pre> <p>However, if you only want some words to be bold or italic. Normally you can set <code>StyleSpan</code> on specific range of your <code>Spannable</code>but it is not work on Chinese word.</p> <p>Therefore, I suggest you create a class extends <code>StyleSpan</code> </p> <pre><code>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 &amp; ~tf.getStyle(); if ((want &amp; Typeface.BOLD) != 0)paint.setFakeBoldText(true); if ((want &amp; Typeface.ITALIC) != 0)paint.setTextSkewX(-0.25f); //The only two lines to be changed, the normal StyleSpan will set you paint to use FakeBold when you want Bold Style but the Typeface return say it don't support it. //However, Chinese words in Android are not bold EVEN THOUGH the typeface return it can bold, so the Chinese with StyleSpan(Bold Style) do not bold at all. //This Custom Class therefore set the paint FakeBold no matter typeface return it can support bold or not. //Italic words would be the same paint.setTypeface(tf); } } </code></pre> <p>Set this span to your Chinese words and I should be work. Be aware to check it is only set on Chinese words only. I have not test on it but I can imagine that set fakebold on a bold English characters would be very ugly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload