본문 바로가기
Programming/Android

Custom Font 사용

안드로이드에선 TTF 또는 OTF (True Type or Open TypeFace, a TTF extension) 설치해서 사용할 수 있다.

Android:typeface 속성 : "normal","sans","serif","monospace"

  1. Project의 assets 하위로 fonts 폴더를 만들고 폰트를 설치
  2. 폰트를 사용할 View 선택
  3. Typeface object 생성(Typeface class static method create())
  4. setTypeface method.

 

Typeface 생성함수

  • create(String familyName, int style);
  • create(TypeFace family, inst style);
  • createFromAsset(AssetManager mgr, String path);
  • createFromFile(File path);
  • createFromFile(String path);

     

     

    TextView v = (TextView) findViewById(R.id.FontView); // 1
    Typeface t = Typeface.createFromAsset(getAssets(),"fonts/fontdemo.ttf");// 2
    v.setTypeface(t, Typeface.BOLD_ITALIC); // 3

     

    FontDemo.zip