Custom font rendering on Android 4.0 (Ice cream sandwich)

后端 未结 4 2136
囚心锁ツ
囚心锁ツ 2021-02-13 03:08

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 d

相关标签:
4条回答
  • 2021-02-13 03:31

    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);
        }
    }
    
    0 讨论(0)
  • 2021-02-13 03:49

    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);
    
    0 讨论(0)
  • 2021-02-13 03:50

    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

    0 讨论(0)
  • 2021-02-13 03:51

    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..

    0 讨论(0)
提交回复
热议问题