Is it possible to set a custom font for entire of application?

后端 未结 25 2964
日久生厌
日久生厌 2020-11-22 02:44

I need to use certain font for my entire application. I have .ttf file for the same. Is it possible to set this as default font, at application start up and then use it else

25条回答
  •  迷失自我
    2020-11-22 03:06

    Yes, its possible to set the font to the entire application.

    The easiest way to accomplish this is to package the desired font(s) with your application.

    To do this, simply create an assets/ folder in the project root, and put your fonts (in TrueType, or TTF, form) in the assets.

    You might, for example, create assets/fonts/ and put your TTF files in there.

    public class FontSampler extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    TextView tv=(TextView)findViewById(R.id.custom);
    
    Typeface face=Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
    tv.setTypeface(face);
    }
    }
    

提交回复
热议问题