Search code examples
androidgraphic

How to draw BIG thin text in android


I need to draw single character on my view as BIG thin text as shown in image below (text as just simple lines)

enter image description here

But my code below gives me following image (text as shape)

    Paint dPaint = new Paint();
    dPaint.setAntiAlias(true);
    dPaint.setDither(true);
    dPaint.setColor(Color.RED);
    dPaint.setTextSize(getWidth()*.8F);
    dPaint.setStyle(Paint.Style.STROKE);
    dPaint.setStrokeWidth(1);
    canvas.drawText("A",getWidth()*.3F, getHeight()*.6F, dPaint);

enter image description here

I tried various paint and stroke properties but none worked out. Also I read the in java 2D text is drawn as shape.

Is there a way to draw text (character in particular) as lines rather then shape. Also text down should be BIG in size.


Solution

  • I think only two ways to achieve your requirement.

    Use a custom font-type with your font style and use it in your application as below

        TextView text = (TextView) findViewById(R.id.textView);
        Typeface customFont = Typeface.createFromAsset(getAssets(), "ThinText.ttf");
        text.setTypeface(customFont);
    

    Another technique is you have to draw the shape of give character as lines by calculating the coordinates required in the path to draw that alphabet or digit.

    I hope it may help you.