android - how to set custom typeface in paint object?

后端 未结 1 328
南笙
南笙 2021-01-27 03:18

I want to use a Paint to draw something and here is my code :

    Paint mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
         


        
相关标签:
1条回答
  • 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

    0 讨论(0)
提交回复
热议问题