Question

I'm trying to add a custom font to my text, but the problem is that the text appears with vertical stripes over it. They aren't in the font and the problem seems to appear only on some Android devices.

This is my TextView

<TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_marginTop="4dip"
    android:layout_marginBottom="4dip"
    android:textColor="#00fff0"
    android:textSize="14sp"
    android:text="Header"/>

and I set the typeface as follows in the onCreate() function

((TextView) findViewById(R.id.header)).setTypeface(Typeface.createFromAsset(this.getAssets(), "bitbold2.ttf"));

The same problem appears also when drawing text on a canvas when initialized like this:

Typeface bitNanoFont = Typeface.createFromAsset(asset, "bitbold2.ttf");
Paint textPaint = new Paint();
textPaint.setARGB(255, 0, 255, 240);
textPaint.setTextSize(24);
textPaint.setTypeface(bitNanoFont);

And drawn like this:

canvas.drawText("Text", 320, 50, textPaint);

The resulting text looks like this (TextView):

The text looks like this.

Image has been scaled upwards and the background is colorful because this image has been taken directly from the application.

Was it helpful?

Solution

This isn't a perfect solution, but I was able to fix the vertical gaps by applying fake bold to the text. This means that Android adds some extra strokes to the letters and thus draws over the gaps.

On TextView

Typeface font = Typeface.createFromAsset(asset, "bitbold2.ttf");
TextView tw = (TextView) findViewById(R.id.header);
tw.setTypeface(font);
tw.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);

and on Canvas

Typeface font = Typeface.createFromAsset(asset, "bitbold2.ttf");
Paint paint = new Paint();
paint.setTypeface(font);
paint.setFakeBoldText(true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top