Search code examples
androidandroid-widgetondrawdrawtexttypeface

custom textview using custom font


I'm trying to implement a custom textview that uses my own custom font.

is there a way to set the typeface before doing a Super.onDraw()?

So as to replace the usual font to the custom font that I want to use.

Something like:

protected void onDraw(Canvas canvas)
{
    Typeface font1 = Typeface.createFromAsset(context.getAssets(), "fonts/myfonts.ttf");
    this.setTypeface(font1);
    this.setTextSize(18);
    super.onDraw(canvas);
}

I know the above code won't work.

Or do I have no choice but to use drawText() to do so?


Solution

  • Oh my bad, it actually does change the font.

    Just that it didn't show up on the preview on Eclipse but it does show on the emulator.

    Problem solved.