2013-10-09 4 views
5

textview 글꼴을 설정하는 데 이상한 문제가 있다고 말하고 싶습니다. 장치 글꼴 스타일을 setting-> display에서 변경하면 textview 글꼴 스타일도 변경됩니다. 이걸 어떻게 막을 수 있습니까?삼성 장치에서 장치 글꼴 스타일을 변경할 때 TextView 글꼴 변경을 방지하는 방법

내 XML 레이아웃의 텍스트 뷰입니다.

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/title_bar_bg" 
     android:fontFamily="sans-serif" 
     android:typeface="sans" 
     android:gravity="center" 
     android:text="@string/people_finder" 
     android:textColor="@color/WHITE" 
     android:textSize="18sp" 
     android:textStyle="bold"> 

    </TextView> 

안드로이드 :의 font는 = "산세 리프" 안드로이드 : 서체 = "산세"또한

그것은 삼성 갤럭시 그랜드 같은 일부 장치에서 잘 작동, 삼성 주 2 하지만 Samsung Note 8, Samsung Note 10.1 등에서 작업하기.

다른 방법이 있습니까?

감사

답변

5

fontFamilytypeface 속성은 안드로이드 기본 글꼴 관련이 있습니다. 장치 글꼴 설정에 관계없이 TextViews 글꼴을 항상 동일하게 지정하려면 프로그래밍 방식으로 사용자 지정 Typeface을 설정해야합니다. 보조 노트로


Typeface tf = Typeface.createFromAsset(context.getAssets(), "fontName.ttf")); 
TextView textView = (TextView) findViewById(R.id.textView1); 
textView.setTypeface(tf); 

, Calligraphy 프로젝트는 실제로 레이아웃 XML에서 직접 사용자 정의 글꼴을 설정 할 수 있습니다.

+1

감사처럼 UR XML에 추가합니다. 작동하지만 네이티브 글꼴을 강제로 설정할 수없는 이유를 알려주십시오. 우리가 모노 스페이스에서 세리프를 사용하는 것처럼 말입니다. 그런 다음 textview.setTypeface (Typeface.MONOSPACE, Typeface.BOLD)와 같이 작동합니다. – Himanshu

+0

다행이었습니다. 디자인적인 결정 일뿐입니다. 그렇습니다. iOS에서도 비슷한 점이 발생합니다. 또한 XML 레이아웃에서 사용자 정의 글꼴을 설정하는 직접적인 방법이없는 이유도 궁금합니다. – ssantos

0
public class CustomTextView extends TextView { 

    Context context; 

    public CustomTextView (Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     this.context = context; 
    } 

    public CustomTextView (Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context = context; 
    } 

    public CustomTextView (Context context) { 
     super(context); 
     this.context = context; 
    } 

    public void setTypeface(Typeface tf, int style) { 
     if (style == Typeface.NORMAL) { 
      super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/HelveticaNeue.ttf")/* 
                              * , 
                              * - 
                              * 1 
                              */); 
     } else if (style == Typeface.ITALIC) { 
      super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/HelveticaNeueItalic.ttf")/* 
                               * , 
                               * - 
                               * 1 
                               */); 
     } else if (style == Typeface.BOLD) { 
      super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/HelveticaNeueBold.ttf")/* 
                               * , 
                               * - 
                               * 1 
                               */); 
     } 
    } 

} 

하고 응답이

<xxx.xxxx.utils.CustomTextView 
     android:id="@+id/login_username_tv" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="0.3" 
     android:text="Email" 
     android:padding="5dp" 
     android:textColor="#333333" 
     android:textSize="12dp"/> 
관련 문제