2012-08-13 6 views
4

내 앱에서 PagerTabStrip으로 ViewPager을 사용하고 있으며 내 위젯에 맞춤 글꼴을 설정해야합니다. 글꼴을 Button 또는 TextView으로 설정하려면 클래스를 확장하고 서체를 설정하면됩니다.TypeFace를 PagerTabStrip 텍스트 뷰로 설정하는 방법

public class MyButton extends Button { 

    public MyButton(Context context) { 
     super(context); 
     initCustomFont(); 
    } 

    public MyButton(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     initCustomFont(); 
    } 

    public MyButton(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     initCustomFont(); 
    } 

    private void initCustomFont() { 
     if(!isInEditMode()) { 
      Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/boton_regular.ttf"); 
      setTypeface(tf); 
     } 
    } 
} 

그러나이 방법은 PagerTabStrip에 사용할 수 없습니다. PagerTabStrip과 함께 사용할 수있는 서체를 설정하는 다른 방법이 있습니까?

답변

20

조금 늦었지만 한 가지 해결책이 있습니다. PagerTabStrip의 자식 뷰를 가져 와서 TextView 인스턴스인지 확인하십시오. 그럴 경우 서체를 설정하십시오.

for (int i = 0; i < pagerTabStrip.getChildCount(); ++i) { 
    View nextChild = pagerTabStrip.getChildAt(i); 
    if (nextChild instanceof TextView) { 
     TextView textViewToConvert = (TextView) nextChild; 
     textViewToConvert.setTypeface(PUT_TYPEFACE_HERE) 
    } 
} 
+0

이것은 가능한 가장 빠른 해결책 일 수 있습니다. 감사합니다.) – ben

+0

동의하지만 다른 소스 코드를 직접 잡아서 수정하는 것 외에는 다른 해결책을 생각할 수 없습니다. PagerTabStrip의 서체를 직접 변경할 수있는 API는 없습니다. – StackOverflower

1

PagerTabStrip으로 계층 구조보기 (응용 프로그램을 실행할 때 이클립스에서 계층 구조보기 퍼스펙티브를 엽니 다)을 검사하고 그 하위 항목을 검색하십시오. 하나는 탭 제목을 보유하는 TextView이어야합니다. 이 TextView을 가져와 서체를 설정하십시오.