1

プロジェクトに別のフォントを割り当てようとしています。新しいフォントをプロジェクト全体で有効にしたいのですが、見つけたのはフォントをテキストビューに変更することだけです

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...");

プロジェクト全体をデフォルトでカスタム フォントにする方法はありますか? 宜しくお願いします

4

2 に答える 2

0

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

これは、TextView がカスタム フォントをサポートするように TextView を拡張し、カスタム属性を使用する方法を示しています。
カスタム フォントと XML レイアウト (Android)

于 2012-04-10T21:19:12.473 に答える
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
    }
}
}
于 2012-04-10T23:29:02.670 に答える