Android custom font loading error

615 views Asked by At

I try to use roboto black font in a textview, but tx.setTypeface(tf); is throwing an error. It says, "Syntax error on token(s), misplaced construct(s)", and at (tf) "Syntax error on token "tf", VariableDeclaratorId expected after this token".

Here is the snippit of code that I'm using to change the font:

TextView tx = (TextView) findViewById(R.id.moomoo);
Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Black.ttf");
tx.setTypeface(tf);

To my knowledge I only have to change the java file, while having the font ttf file in my assets folder, in a child of the assets folder called "fonts". I then just need a reference to the text view and can do everything from the constructor of the java class for the xml file's font that I'm trying to change, correct? Is my logic flawed, what am I doing wrong? Android is version 19.

1

There are 1 answers

1
user3576305 On

Change

Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Black.ttf");

to

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Black.ttf");