2014-09-13 3 views
0

나는, 설정 안드로이드 글꼴 로컬

<!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
     <item name="android:textViewStyle">@style/RobotoTextViewStyle</item> 
     <item name="android:buttonStyle">@style/RobotoButtonStyle</item> 
    </style> 

    <style name="RobotoTextViewStyle" parent="android:Widget.TextView"> 
     <item name="android:fontFamily">sans-serif-light</item> 
    </style> 

    <style name="RobotoButtonStyle" parent="android:Widget.Holo.Button"> 
     <item name="android:fontFamily">sans-serif-light</item> 
    </style> 

그리고 매니페스트 파일에

나는

android:theme="@style/AppTheme" 

하지만 여전히 나는 안드로이드에서 프로그램을 실행 4.4.2 주 3 다음 다래끼 코드 설정을 가지고있다 , 만화는 여전히 사용되는 글꼴을, 어떤 이유가 있습니까?

답변

1

은 당신의 자산 글꼴 폴더를 생성하고 해당 폴더에 글꼴을 넣어보다

public class TypefaceClass { 


    public static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>(); 

    public static Typeface get(Context context, String assetPath) { 
     synchronized (cache) { 
      if (!cache.containsKey(assetPath)) { 
       try { 
        Typeface t = Typeface.createFromAsset(context.getAssets(), 
          assetPath); 
        cache.put(assetPath, t); 
       } catch (Exception e) {      
        return null; 
       } 
      } 
      return cache.get(assetPath); 
     } 
    } 
} 

같은 서체 클래스를 작성하려고합니다. 그런 다음 위 유형 서 클래스를 사용하여 setTypeface를 작성하십시오.

textView.setTypeface(TypefaceClass.get(context, 
       "font/your_font.ttf")); 

작동하지 않는 경우 .ttf 파일 대신 .otf 파일을 사용해보십시오. 그것은 분명히 당신의 문제를 해결할 것입니다. 4.4 위의 .ttf 파일에는 몇 가지 문제가 있습니다. 글꼴의 .otf 파일을 가져 오십시오.

+0

이전 접근 방식의 문제점은 무엇입니까? 나도 그 쓰레드 중 하나에서 얻었 어. – cherhan