문제

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 with scary red lines, it says

The method getAssets() is undefined for the type ProfileFragment

ProfileFragment is the name of my class and it extends Fragment.

NOTE : The font style is also on the assets folder.

도움이 되었습니까?

해결책

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


Use this

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

instead of

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

Read more about Set custom font for Android fragments

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top