Question

While testing an application that uses Helvetica Neue as its primary font on Android 4.0 I have found that there is an inconsistency in typeface rendering compared to multiple different version of Android. We tested this on 2.1, 2.2.2, 2.3.5, 3.2, 4.0, and 4.0.3 with the same results every time. We also did these tests with different typeface binaries with the same results.

Any input or workarounds would be appreciated.

Below is a screenshot from an example application to show the undesired results, the first is 2.3.5 the second is 4.0.3.

2.3.5

4.0.3

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textView = new TextView(this);
    textView.setText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
    textView.setTypeface(Typeface.createFromAsset(getAssets(), "Helvetica Neue.ttf"));
    textView.setTextSize(9);
    setContentView(textView);
}
Was it helpful?

Solution

Although we never found a solution to the Helvetica rendering bug we were able to convince the client to switch to Roboto after we showed them the bug on a Galaxy Nexus.


Update:

public class TextViewCompat extends TextView {

    public TextViewCompat(Context context) {
        super(context);
        setup(context, null, 0);
    }

    public TextViewCompat(Context context, AttributeSet attrs) {
        super(context, attrs);
        setup(context, attrs, 0);
    }

    public TextViewCompat(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setup(context, attrs, defStyle);
    }

    private void setup(Context context, AttributeSet attrs, int defStyle) {
        setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    }
}

OTHER TIPS

Add font type ttf file to asset folder, then add below code

Typeface tf = Typeface.createFromAsset(getBaseContext().getAssets(), "Helvetica.ttf");

then add tf object to text view as below

textobjext.setTypeface(tf, Typeface.BOLD);

After playing some more I haven't been able to reproduce what you see.

Leads me to believe that the the font you are using is bad.

I set all my typefaces as per my other answer, this works fine for me, see screens:

So the top text is Roboto-Normal Then the text below is Roboto-Light, with <b></b> for making it strong.

So 3 versions, 3 different screen sizes, two densities, manually set Typeface. same rendering. Not sure how your getting what your seeing. Have you tried with a different typeface?

I'll provide some more examples of what i'm doing if that might help?

Android 2.2

Android 2.3

Android 4.0.3

ICS v14+ uses the Roboto font found here:Android design

It would be better to set the type face manually if you want it to display the same across all versions.

Typeface mBoldType = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf");
TextView mTextView = findById(R.id.text1);
mTextView.setTypeface(mBoldType);

Unfortunately there is no quick way to do this in the xml for custom fonts, but a properly programed Helper class should do what you need.

If you need a example function let me know.

What should be noted, is that if you set a custom typeface, things like android:fontStyle will not work, ie, you need a bold typeface, italic typeface etc..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top