如何在 Android 设备上使用编程无需 Root 来安装 Font?

How to install Font in Android device using programing without Root?

我想在我的应用程序启动时在 android 设备中安装 .ttf 文件的自定义字体。实际上,当我 运行 我的应用程序时,我需要在我的 android 设备中安装古吉拉特语字体。可能吗 ?如果是那么怎么办?谢谢。我不需要字体..我想在没有根设备的情况下安装在系统设置中

没有其他方法可以在没有 root 的情况下从您的应用程序安装字体,只有当您将 shruti.ttf 文件放入 assert 文件夹时才有可能

Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/verdana.ttf");  
textfield.setTypeface(tf,Typeface.BOLD);

你也可以通过扩展其他控件来设置你的字体ex.TextView

public class TextViewWithFont extends TextView {
private int defaultDimension = 0;
private int TYPE_BOLD = 1;
private int TYPE_ITALIC = 2;
private int FONT_ARIAL = 1;
private int FONT_OPEN_SANS = 2;
private int fontType;
private int fontName;

public TextViewWithFont(Context context) {
    super(context);
    init(null, 0);
}
public TextViewWithFont(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(attrs, 0);
}
public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(attrs, defStyle);
}
private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.font, defStyle, 0);
    fontName = a.getInt(R.styleable.font_name, defaultDimension);
    fontType = a.getInt(R.styleable.font_type, defaultDimension);
    a.recycle();
    MyApplication application = (MyApplication ) getContext().getApplicationContext();
    if (fontName == FONT_ARIAL) {
        setFontType(application .getArialFont());
    } else if (fontName == FONT_OPEN_SANS) {
        setFontType(application .getOpenSans());
    }
}
private void setFontType(Typeface font) {
    if (fontType == TYPE_BOLD) {
        setTypeface(font, Typeface.BOLD);
    } else if (fontType == TYPE_ITALIC) {
        setTypeface(font, Typeface.ITALIC);
    } else {
        setTypeface(font);
    }
}
}