Skip to content Skip to sidebar Skip to footer

Initialize Typeface In A Fragment

i have this line : Typeface font = Typeface.createFromAsset(getAssets(), 'fonts/Delius-Regular.ttf'); but the getAssets() parameter seems to bring some error, it is underlined wit

Solution 1:

You cannot get getAssets() from a fragment directly. You have to use getActivity().getAssets() instead of using only getAssets().


Use this

Typefacefont= Typeface.createFromAsset(getActivity().getAssets(), "fonts/Delius-Regular.ttf");

instead of

Typefacefont= Typeface.createFromAsset(getAssets(), "fonts/Delius-Regular.ttf");

Read more about Set custom font for Android fragments

Post a Comment for "Initialize Typeface In A Fragment"