Search code examples
javaandroidtextviewandroid-typeface

Setting custom font programmatically


Fairly straightforward. It doesn't seem to be wanting to work for me. The error I get is that getAssets() is red and it says Cannot resolve method 'getAssets()'.

    text_View = (TextView) this.view.findViewById(R.id.textDesigner);
    Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/Calligraffitti-Regular.ttf");
    text_View.setTypeface(myTypeface);

The path for my font is: C:\Users\Joe\AndroidStudioProjects\my-app\app\src\main\assets\fonts\Calligraffitti-Regular.ttf

What's going on?


Solution

  • try to call the fragment's activity and then the assets

    getActivity().getAssets()