2013-10-09 24 views
5

Aygıt font stilini değiştirdiğimizde, TextView yazı tipinin nasıl değiştirileceğini engellemek için metin görünümü yazı tipini ayarlamada garip bir sorun olduğunu söylemek isterim. Cihaz yazı tipi stilini ayar-> ekrandan değiştirirsem, yazı tipi stili de değiştirilir. Bunu nasıl önleyebilirim?Samsung cihazları

Metin düzenimin xml düzenimde.

<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> 

android: fontFamily = "sans-serif" android: yazı tipi = "sans" Ayrıca

O Samsung Galaxy Grand, gibi bazı cihazda iyi çalışıyor, Samsung Note 2 Ama Samsung Note 8, Samsung Not 10.1 vb. çalışmalarında, bunu yapmak için başka bir yol var mı?

Teşekkür

cevap

5

fontFamily ve typeface nitelikleri android yerli yazı ile ilişkilidir. TextViews yazı tipinizin cihaz yazı tipi ayarlarına bakmaksızın her zaman aynı olmasını istiyorsanız, programlı olarak bir özel Typeface ayarlamanız gerekir. Bir yan not olarak


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

, Calligraphy proje aslında bir düzen xml doğrudan özel yazı tipi belirlenmesine imkan verir.

+1

teşekkür gibi ur xml ekleyin. Çalışıyor, ancak Yerli yazı tiplerini neden güçlü bir şekilde ayarlayamadığımızı bana bildirir misiniz? Tek boşlukta serif kullanıyormuşuz gibi. o zaman aynı zamanda textview.setTypeface (Typeface.MONOSPACE, Typeface.BOLD); – Himanshu

+0

Çalıştığına sevindim :) Sanırım bu sadece bir tasarım kararı, ancak evet, iOS'ta benzer bir şey oluyor; Ayrıca xml düzenlerinden özel yazı tiplerini ayarlamak için neden düz bir yol olmadığını merak ediyorum. – 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 
                               */); 
     } 
    } 

} 

ve Yanıtınız için bu

<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"/> 
İlgili konular