Adding text to ImageView in Android

后端 未结 9 1680
北荒
北荒 2020-12-02 16:44

I want to use an ImageView to show some message in a fancy way.

How do I add text to an ImageView?

9条回答
  •  孤城傲影
    2020-12-02 17:05

    To draw text directly on canvas do the following:

    1. Create a member Paint object in myImageView constructor

      Paint mTextPaint = new Paint();
      
    2. Use canvas.drawText in your myImageView.onDraw() method:

      canvas.drawText("My fancy text", xpos, ypos, mTextPaint);
      

    Explore Paint and Canvas class documentation to add fancy effects.

提交回复
热议问题