android:关于字体问题

1:全局替换字体

mainfest.xml文件引入

android:theme="@style/AppTheme"

 style.xml中加入

<item name="android:fontFamily">@font/fangsong</item>

 字体放在res/font下面

2:自定义application中创建Typeface,使用的时候调用就行,或者直接工具类里面创建(没有尝试过)

public class MyApplication extends Application {
    public static Typeface fangsong;

    @Override
    public void onCreate() {
        super.onCreate();
        fangsong=Typeface.createFromAsset(getAssets(), "fonts/fangsong.ttf");
    }

}

3:使用的时候再创建(不推荐)

TextView textView = R.findViewByid();

textView.setTypeface(

Typeface.createFromAsset(getAssets(), "fonts/fangsong.ttf")

)

 不推荐的原因是因为加载字体需要时间,每次使用再创建严重影响性能

猜你喜欢

转载自blog.csdn.net/GZ_public/article/details/127801837