2012-04-10 22 views
1

私のプロジェクトに別のフォントを割り当てようとしています。 私は新しいフォントがプロジェクト全体のために有効ですしたいが、私は見つけることはすべてのTextViewandroid projectのカスタムフォント

Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/RockFont.ttf"); 
TextView customText1 = (TextView)findViewById(R.id.text1); 
customText1.setTypeface(font1); 
customText1.setTextSize(40.f); 
customText1.setText("Hello! This is a custom font..."); 

あり、プロジェクト全体にカスタムフォントをデフォルトにどのような方法にフォントを変更するのですか? 最高のお礼

答えて

0

あなたが求めているものではありませんが、上記のコメントに基づいて、デフォルトのコントロールでカスタムフォントを使用する方が簡単です。

TextViewがカスタムフォントをサポートするように、TextViewを拡張しカスタム属性を使用する方法を示します。
Custom fonts and XML layouts (Android)

0

私がやっていることは、サポートクラスを作成し、それを自分のアクティビティからインスタンス化し、私がスタイルを設定したいすべてのビューを通過させることです。

public class textfactory{ 
private TextView tv; 
private Button b; 
private RadioButton rb; 

private TypeFace font; 

/** 
* fetch font resource 
*/ 
public textfactory(Context context){ 
    this.font = Typeface.createFromAsset(context.getAssets(), 'customfont.ttf'); 
} 
/** 
* pass in all the views you wish to apply font to 
*/ 
public void style(View... views){ 
    for(View v : views){ 
     if(v instance of TextView) 
     { 
      tv = (TextView)v; 
      tv.setTypeface(this.font); 
     } 
     else if(v instance of Button) 
     { 
      b = (Button)v; 
      b.setTypeface(this.font); 
     } 
     else if(v instance of RadioButton) 
     { 
      rb = (RadioButton)v; 
      rb.setTypeface(this.font); 
     } 
     //add as many view conditionals as required 
    } 
} 
}