Android - Using Custom Font

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

    You can use easy & simple EasyFonts third party library to set variety of custom fonts to your TextView. By using this library you should not have to worry about downloading and adding fonts into the assets/fonts folder. Also about Typeface object creation.

    Instead of

    Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/myFont.ttf");
    TextView myTextView = (TextView)findViewById(R.id.myTextView);
    myTextView.setTypeface(myTypeface);
    

    Simply:

    TextView myTextView = (TextView)findViewById(R.id.myTextView);
    myTextView.setTypeface(EasyFonts.robotoThin(this));
    

    This library also provides following font face.

    • Roboto
    • Droid Serif
    • Droid Robot
    • Freedom
    • Fun Raiser
    • Android Nation
    • Green Avocado
    • Recognition

提交回复
热议问题