android set custom font to a paint

后端 未结 5 2301
难免孤独
难免孤独 2020-11-30 23:16

I want to draw a text to a paint. How to draw it with a custom font (ex Helvetica ) and bold also? I would preffer to use a system font and not create it fr

5条回答
  •  Happy的楠姐
    2020-11-30 23:47

    If you already have a font in use and want to use a bold version of that you can do this.

    currentPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    currentPainter.setColor(Color.WHITE);
    currentPainter.setTextSize(Utils.sp2px(getResources(), 14)); // set font size
    Typeface currentTypeFace =   currentPainter.getTypeface();
    Typeface bold = Typeface.create(currentTypeFace, Typeface.BOLD);
    currentPainter.setTypeface(bold);
    

    I used the answer above, but this modification was necessary for me - so just thought I'd mention it

提交回复
热议问题