Android更改整个应用程序的字体

标签 android

在我的 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/

相关文章:

android - 如何向 WindowManager 添加 Activity

android - Recyclerview 将 ID 从数组传递到另一个 Activity onClick 返回随机 id

安卓-java.io.IOException : Canceled when disposed

android - 将驱动程序添加到 Android 设备内核

android - 销毁 Activity 堆栈

java - 不能使用公共(public)静态方法?

java - 我在这里制造内存泄漏吗?

android - 谷歌地图在位置更新时返回 null

android - 将 Android 位图转换为 OpenCV Mat 并向后转换

android - Sqlite 管理器的图标没有出现