Html in text view with different fonts for bold and italic

前端 未结 4 1232
忘掉有多难
忘掉有多难 2021-01-05 03:46

I\'m trying to use a custom font on a TextView. The TextView text is set with textView1.setText(Html.fromHtml(htmlText));

The

4条回答
  •  离开以前
    2021-01-05 04:15

    I imagine you want to do a quick refactor on your code in order to incorporate the assets.

    I would extend TextView and attempt to parse the HTML and apply the proper typeface at onDraw.

    Override setText and parse the parameter creating a Map for character and the proper typeface that should be used.

    Then, override onDraw and before drawing, change the typeface of super.getPaint() in accord to the Map you created on the previous step.

    The code should look something as the one presented in onDraw method from How to correctly draw text in an extended class for TextView?, however you will set the previously determined typeface instead of applying super.getTypeface().

    Hope it helps you

提交回复
热议问题