2012-02-17 8 views
0

나는 안드로이드에서 사용자 정의 글꼴에 속고있다. 나는 폰트를 가져와 그 폰트로 설정된 텍스트보기를 가져 오는 방법을 안다. 나는 일단 많은 textView가 있으면 오히려 지루해 질 수 있다는 것을 알아 챘다.android의 전체 레이아웃에 글꼴 설정

전체 레이아웃 글꼴 유형을 특정 글꼴로 설정하는 방법이 있습니까?

미리 감사드립니다. 나는 완전한 이름을 사용하는 경우

내 레이아웃에서 다음
public class MyTextView extends TextView { 

public MyTextView(Context context) { 
    super(context); 
    setTypeFace(); 
} 


public MyTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    setTypeFace(); 
} 


public MyTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    setTypeFace(); 
} 

public void setTypeFace() 
{ 
    this.setTypeface(StaticUtils.getDefaultFontNormal(getContext())); 
} 

} 

는, 작동 :이 같은 생성자에서 서체를 설정 어디 무슨 짓을

+1

이 질문보기 : http://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android – howettl

답변

1

는 텍스트 뷰 내 자신의 하위 클래스를 선언했다 :

<ca.mycompany.mobile.ui.support.MyTextView 
     android:id="@+id/title_summaryreports" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingBottom="10dip" 
      android:paddingTop="10dip" 
      android:text="@string/title_strategies" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textStyle="bold" 
      android:textColor="#ff0000" /> 
0

이 방법을 사용하면 최상위 수준의보기 그룹 id와 글꼴 유형 서체를이 방법에 전달하면 전체 레이아웃으로 글꼴이 설정됩니다.

public void setFont(ViewGroup group, Typeface lTypeface) 
{ 
    int count = group.getChildCount(); 
    View v; 
    for (int i = 0; i < count; i++) 
    { 
     v = group.getChildAt(i); 
     if (v instanceof TextView) 
     { 
      ((TextView) v).setTypeface(lTypeface); 
     } else if (v instanceof EditText) 
     { 
      ((EditText) v).setTypeface(lTypeface); 
     } else if (v instanceof Button) 
     { 
      ((Button) v).setTypeface(lTypeface); 
     } else if (v instanceof TextInputLayout) 
     { 
      ((TextInputLayout) v).setTypeface(lTypeface); 
     } else if (v instanceof ViewGroup) 
      setFont((ViewGroup) v, lTypeface); 
    } 
}