2012-02-22 3 views
5

Ben android bir acemi. Ben Android'de bir Textview yazı tipi değiştirmek mümkün olabilir.Ama varlık .ttf dosya kullanmak zorunda Bu tür yazı tiplerini değiştirmek içinbir Edittext, Radyo Düğmesi ve CheckBox yazı tipi türünü değiştirebilir Android

TextView text = (TextView) layout.findViewById(R.id.text); 
text.setText(msg); 
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/handsean.ttf"); 
text.setTypeface(font); 

Yukarıdaki kod ben Im de benim uygulamada kullanılan kutu (Radyo Düğmesi, EditText metninin yazı tipini değiştirmek ve kontrol gerekiyor view.but bir metnin yazı tipini değiştirmek için kullanılan budur) de.Plz burada bana yardım edin. Şimdiden teşekkürler.

+0

senin de diğer görünümler için aynı kodu kullanmak zorunda, sanırım. Kodu EditText vb. Kullanarak kullanmayı denediniz mi? – noob

+0

Evet, aynı kodu edittext için de kullanmanız gerekiyor. – AndoAiron

cevap

6

Evet u çok EditText, CheckBox gibi diğer kontroller için çalışacak here.This belirtmiştik wht aynı kodu takip etmek zorunda vb

+2

kod nerede? –

0

Evet aynı yaklaşım çok düğme ve radyo düğmeleri için çalışacaktır.

Button moreBtn = (Button) events.findViewById(R.id.promotion_event_more_btn); 
FontUtils.setTypeface(this, moreBtn, Constants.C_FONT);</code><br>Where "Constants.C_FONT" is set to the path of the font file present in the assets folder. 
0

aşağıdaki siz de .xml dosyasında yüzden bunu yapabilir olarak
Ayrıca basit adımda bunu yapabilirsiniz

bunu

android:textSize="20dp" 
    android:textStyle="bold" 
    android:textColor="any color" 
    android:textAppearance="any appearencde" 

kullanabilirsiniz yapmak proertiees kullanabilirsiniz bu düğmeler, kutu kutuları vb. ile

u da şu kodu kullanarak yapabilirsiniz

3

seçilen yanıtlama kodu eksikti, işte o:

EditText

EditText editText = (EditText) layout.findViewById(R.id.edittext); 
editText.setText(msg); 
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf"); 
editText.setTypeface(font); 

RadioButton

RadioButton radioButton = (RadioButton) layout.findViewById(R.id.radiobutton); 
radioButton.setText(msg); 
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/myfont.ttf"); 
radioButton.setTypeface(font); 

CheckBox

CheckBox checkBox = (CheckBox) layout.findViewById(R.id.checkbox); 
checkBox.setText(msg); 
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf"); 
checkBox.setTypeface(font); 

Çoklu Görüntüleme

uygulamanıza genelinde birden görünümler için bunu yapmak gerekiyorsa

, o zaman senin EditText, RadioButton veya CheckBox bir alt sınıfı yapmak daha kolay olabilir. Bu alt sınıf yazı tipini ayarlar. Aşağıda, CheckBox için bir örnek verilmiştir.

public class MyCheckBox extends CheckBox { 

    // Constructors 
    public MyCheckBox(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     init(); 
    } 
    public MyCheckBox(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 
    public MyCheckBox(Context context) { 
     super(context); 
     init(); 
    } 

    // This class requires myfont.ttf to be in the assets/fonts folder 
    private void init() { 
     Typeface tf = Typeface.createFromAsset(getContext().getAssets(), 
       "fonts/myfont.ttf"); 
     setTypeface(tf); 
    } 
} 

aşağıdaki gibi xml kullanılabilir:

<com.example.projectname.MyCheckBox 
    android:id="@+id/checkbox" 
    android:text="@string/msg" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:checked="true"/>