3

I'm trying to use custom fonts in an android wear app, but until now no success. I can't find any specific documentation about using custom typefaces for android wear and tried to apply the same method for normal android apps.

  • I created a assets folder in my project by using android studio and created a folder inside it named fonts. I placed the font file in this folder.

  • In the onCreate() method i added following line to load font as a typeface.

    mTypeface = Typeface.createFromAsset(getBaseContext().getAssets(), "fonts/fontawesome-webfont.ttf");
    
  • And finally created a Paint object and set the typeface

    paint.setTypeface(mTypeface);
    

But canvas.drawText() doesn't draw desired fonts.

My question is, is it even possible to use custom typefaces in an android wear application? If yes, how?

Thanks.

2 Answers 2

1

Maybe you forgot to pass the Paint parameter to the drawText method like this:

canvas.drawText("Sample text in bold",0,0, paint);

Notice the fourth parameter, if you don't specify which paint will draw the text, it won't draw like that.

Hope I help someone.

Sign up to request clarification or add additional context in comments.

Comments

0

I've used custom fonts multitudes of time for Android Wear watch faces, but I don't see why it should be any different for creating standalone applications. Have you tried other fonts?

I'm building a wear app for a client at the moment, but I'm not at the stage where I need to change the typeface yet. I can try this for you however and see if I experience same results.

3 Comments

Hi thanks for clearing. I tried actually with multiple ttf fonts to achieve custom typeface, but it doesn't work. It seems all of them was not compatible with android (why android silently fails and not accepts these fonts, is another question). I just tried to use a library called EasyFonts (android-arsenal.com/details/1/2044) and it works without any problem.
Glad it worked out for you. I tried quickly to change the typeface and it didn't seem like it produced any results, weird? I'll post later if I find a proper solution. That's a sweet library, too.
The open sourced fonts from google fonts seems working without any problem. All fonts I tried just worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.