How android set custom font in canvas?

后端 未结 3 1318
独厮守ぢ
独厮守ぢ 2021-02-15 15:54

hi i want to change my font size by using paint , canvas in android. My code is here. how can i do this ?

public class MainActivity extends Activity 

{
@Overrid         


        
相关标签:
3条回答
  • 2021-02-15 16:03

    Use this:

       Typeface tf = Typeface.createFromAsset(getAssets(),"RECOGNITION.ttf");
       Paint paint = new Paint();
       paint.setTypeface(tf);
       canvas.drawText("Sample text in bold RECOGNITION",0,0,paint);
    
    0 讨论(0)
  • 2021-02-15 16:05

    Use the next:

     Paint paint = new Paint();
     paint.setTypeface(tf);
     paint.setTextSize(yourTextSize);
     canvas.drawText("Lorem ipsum", 0, 0, paint);
    
    0 讨论(0)
  • 2021-02-15 16:19

    create "fonts" folder under "assets" folder. After that put your font file in "fonts" folder and write below code.

       Typeface tf =Typeface.createFromAsset(getAssets(),"fonts/YOURFONT.ttf");
       Paint paint = new Paint();
       paint.setTypeface(tf);
       canvas.drawText("Sample text in bold RECOGNITION",0,0,paint);
    
    0 讨论(0)
提交回复
热议问题