Android Typeface createFromAsset

后端 未结 7 2132
滥情空心
滥情空心 2020-12-14 14:49

I Have a Custom View which draws text onto the Canvas. I want to change the font to a font stored in the assets folder.

I

7条回答
  •  Happy的楠姐
    2020-12-14 15:01

    In order to reuse typefaces in my projects I create a class full of typeface methods, this way I dont have to create a new typeface every time.

    I call the class FontClass and in the class there is a method for each typeface I need to use e.g:

    public static Typeface getOpenSansRegular(Context c){
        return Typeface.createFromAsset(c.getAssets(), "OpenSans-Light.ttf");
    }
    

    Then I can use them like so:

    TextView text = (TextView) findViewById(R.id.textview);
    text.setTypeface(FontClass.getOpenSansRegular(getApplicationContext());
    

提交回复
热议问题