2013-10-14 4 views
5

Android에서 글꼴을 설정하는 여러 가지 방법이 있습니다. 내가해야 할 일은 글꼴을 custom font과 조합하여 entire app 이상으로 설정하는 것입니다.전체 앱에 사용되는 맞춤 글꼴

일부 연구를 마친 후 2 가지 옵션이 있습니다.

  • EditText을 덮어 쓰고 글꼴을 설정하려면 레이아웃 xml에이 클래스를 사용하십시오.
  • 내 styles.xml에 내 AppTheme에 글꼴을 추가하십시오.

이제는 내 전체 앱에서 동일한 글꼴을 사용하기 때문에 마지막 옵션을 선호합니다. 이것은 내 위치에서 가장 좋은 방법입니다. 이제 문제는 내 Assets/font/ 폴더에 내가 사용하고 싶은 글꼴을 추가했는데 내 스타일에서 사용할 수 없다는 것입니다.

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:typeface"> Here? </item> 
</style> 

글꼴을 서체로 추가하는 방법. 그게 가능하니?

답변

0

이 코드를보십시오 : 다음 XMLwith에 사용

public class CustomTextView extends EditText { 

public CustomTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    if (!isInEditMode()) 
     init(); 

} 

public CustomTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    if (!isInEditMode()) 
     init(); 

} 

public CustomTextView(Context context) { 
    super(context); 
    if (!isInEditMode()) 
     init(); 
} 

public void init() { 
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), Constants.FONTPATH); 
    setTypeface(tf); 

} 

    } 

을;

 <pkgname.CustomTextView android:id="@+id/txt" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
+0

그건 내 질문이 아니야. 이것은 나의 첫번째 선택이었다. 그리고 내가 언급 한대로 편집 텍스트가 아닌 텍스트 뷰를 덮어 씁니다. 그러나 이것의 옆에, 나는이 선택권 및 나의 위치에서 가장 능률적 인 방법 아닙니다 cognize. 그것은 계획과 같습니다. b. –

0

xml 파일의 외부 자산에 액세스 할 수있는 방법은 없습니다.

+0

그동안 나는이 문제를 해결할 방법을 찾지 못했습니다. 난 그냥 사용자 정의 Textview와 함께 간다. 미래에 이런 일이 있기를 바랍니다. 코드를 훨씬 더 깔끔하게 만듭니다. –