Android - Using Custom Font

后端 未结 21 1661
别跟我提以往
别跟我提以往 2020-11-22 04:38

I applied a custom font to a TextView, but it doesn\'t seems to change the typeface.

Here is my code:

    Typeface myTypeface = Typeface         


        
21条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 05:35

    For Custom Fonts in android create a folder within assets folder name it "fonts" place your desired fonts.ttf or .otf file in it.

    If you extends UIBaseFragment:

    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Arial.ttf");
            tv.setTypeface(font);
    

    else if extends Activity:

    Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/Arial.ttf");
            tv.setTypeface(font);
    

提交回复
热议问题