Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将字体设置为CustomView';Android中的文本是什么?_Java_Android_Textview_Typeface - Fatal编程技术网

Java 如何将字体设置为CustomView';Android中的文本是什么?

Java 如何将字体设置为CustomView';Android中的文本是什么?,java,android,textview,typeface,Java,Android,Textview,Typeface,我试图在Android中绘制一个弧形文本。这是我的CustomView: public class GraphicsView extends View { private static final String MY_TEXT = "xjaphx: Draw Text on Curve"; private Path mArc; private Paint mPaintText; public GraphicsView(Context context) {

我试图在Android中绘制一个弧形文本。这是我的
CustomView

public class GraphicsView extends View {
    private static final String MY_TEXT = "xjaphx: Draw Text on Curve";
    private Path mArc;

    private Paint mPaintText;

    public GraphicsView(Context context) {
      super(context);     

      mArc = new Path();
      RectF oval = new RectF(50,100,200,250);;
      mArc.addArc(oval, -180, 200);          
      mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
      mPaintText.setStyle(Paint.Style.FILL_AND_STROKE);
      mPaintText.setColor(Color.WHITE);
      mPaintText.setTextSize(20f);

    }

    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawTextOnPath(MY_TEXT, mArc, 0, 20, mPaintText);      
      invalidate();
    }
  }

我想更改我的文本字体。我该怎么做?谢谢。

您可以通过这种方式将自定义字体设置为绘画

Typeface plain = Typeface.createFromAsset(assetManager, pathToFont); 
Typeface bold = Typeface.create(plain, Typeface.DEFAULT_BOLD)
Paint paint = new Paint();
paint.setTypeface(bold);