android - how to set custom typeface in paint object?

放肆的年华 提交于 2019-12-02 02:54:59

try this:

    Typeface tf =Typeface.createFromAsset(getAssets(),"fonts/iran_sans_.ttf");
   Paint paint = new Paint();
   paint.setTypeface(tf);
   canvas.drawText("Sample text",0,0,paint);

you can also use the Textpaint class instead of Paint

   TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(20);
    textPaint.setTextAlign(Paint.Align.LEFT);
    textPaint.setColor(Color.WHITE);
    Typeface tf =Typeface.createFromAsset(getAssets(),"fonts/iran_sans_.ttf");
    textPaint.setTypeface(tf);

see this: https://developer.android.com/reference/android/text/TextPaint.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!