1

I am trying to assign a different font to my project. I want the new font is valid for the entire project, but all I find is to change the font to a textview

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

There any way to default to the entire project a custom font? Best regard

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