0

i have Helvetica Neue.ttf in asset Folder , How to set the Helvetica Neue textStyle on My Entire Applcation.

sunil
  • 300
  • 3
  • 20
  • You'll have to subclass e.g. TextView and set the typeface in the subclass' constructor... then use this subclass everywhere instead of TextView. – ElDuderino Jun 12 '14 at 13:47
  • possible duplicate of [How to change fontFamily of TextView in Android](http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android) – 323go Jun 12 '14 at 13:52

1 Answers1

0

There is currently no way to do this with the Views that come with the Android SDK. You can set your View to use any of the Roboto fonts as per this answer, but you cannot set a custom font.

The way I typically tackle this problem is to create my own TextView that uses my font, like so:

public class MyFontTextView extends TextView {
    public static final String FONT_PATH = "fonts/MyFont.ttf";

    public MyFontTextView(Context context) {
        super(context);
        initFont();
    }

    public MyFontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initFont();
    }

    public MyFontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initFont();
    }

    /**
     * Set up the font.
     */
    private void initFont() {
        if (!isInEditMode()) {
            Typeface font = Typeface.createFromAsset(getContext().getAssets(), FONT_PATH);
            setTypeface(font);
        }
    }
}

You replace all of your TextViews with this TextView, and then you will have your font. Note that other UI elements (e.g. Buttons) will still use Roboto unless you also customize those.

If you have a View that you only use once in your application, you could call setTypeFace() on that View instead of creating a custom View. The custom View method works well for Views that you use a lot in an application such as TextViews.

Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120