Android - Using Custom Font

后端 未结 21 1979
别跟我提以往
别跟我提以往 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条回答
  •  醉梦人生
    2020-11-22 05:13

    With Android 8.0 using Custom Fonts in Application became easy with downloadable fonts. We can add fonts directly to the res/font/ folder in the project folder, and in doing so, the fonts become automatically available in Android Studio.

    Now set fontFamily attribute to list of fonts or click on more and select font of your choice. This will add tools:fontFamily="@font/your_font_file" line to your TextView.

    This will Automatically generate few files.

    1. In values folder it will create fonts_certs.xml.

    2. In Manifest it will add this lines:

       
    

    3. preloaded_fonts.xml

    
        
            @font/open_sans_regular
            @font/open_sans_semibold
        
    
    

提交回复
热议问题