在我的 android 应用程序中,我想更改所有文本的字体。我知道如何使用 Assets 更改 textview、按钮、微调器等的字体。但我想用一种简单的方法更改整个应用程序的字体??任何帮助将不胜感激
最佳答案
实现字体的两种方式:
1)您必须创建自己的 TextView 或按钮 View 类。
2)你可以使用通用方法:
//use Singleton Design Pattern for better performance
public class CommonMethod{
public static Typeface getFontTypeface()
{
Typeface mTypeface = null;
if(mTypeface == null)
{
mTypeface = Typeface.createFromAsset(mContext.getAssets(),"Helvetica_.ttf");
}
return mTypeface;
}
public static void SetTypeface(Activity activity, TextView... edt) {
for (int i = 0; i < edt.length; i++) {
edt[i].setTypeface(getFontTypeface());
}
}
}
并像这样在您的所有 Activity 中设置此功能:
CommonMethod.SetTypeface(getActivity(), txtfragedit, txtYoutube,
txtFacebook, txtTwitter);
希望有用。
如果您的应用程序已完成,则第二种方法更可取。如果您现在开始构建应用程序,则第一种方法更可取。
关于Android更改整个应用程序的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22470830/