Android - Using Custom Font

后端 未结 21 1660
别跟我提以往
别跟我提以往 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:21

    The best way to do it From Android O preview release is this way:

    It works only if you have android studio-2.4 or above

    1. Right-click the res folder and go to New > Android resource directory. The New
      Resource Directory window appears.
    2. In the Resource type list, select font, and then click OK.
    3. Add your font files in the font folder.The folder structure below generates R.font.dancing_script, R.font.la_la, and R.font.ba_ba.
    4. Double-click a font file to preview the file's fonts in the editor.

    Next we must create a font family:

    1. Right-click the font folder and go to New > Font resource file. The New Resource File window appears.
    2. Enter the File Name, and then click OK. The new font resource XML opens in the editor.
    3. Enclose each font file, style, and weight attribute in the font tag element. The following XML illustrates adding font-related attributes in the font resource XML:

    Adding fonts to a TextView:

       
    

    As from the documentation

    Working With Fonts

    All the steps are correct.

提交回复
热议问题