【问题标题】:How to install Font in Android device using programing without Root? [duplicate]如何在没有 Root 的情况下使用编程在 Android 设备中安装字体? [复制]
【发布时间】:2016-02-10 06:54:33
【问题描述】:

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

【问题讨论】:

  • 不可能,因为所有字体相关的文件夹都在根目录中。并且根目录没有root是无法访问的。
  • 但是如果你不将它包含在你的应用程序中,那么如果你发布应用程序,没有人会拥有它.....这真的是你想要的吗?
  • 如果您阅读古吉拉特语字体,那么您可以使用应用程序。可以翻译您选择的文本。

标签: android fonts typeface android-fonts android-typeface


【解决方案1】:

没有其他方法可以在没有 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);
    }
}
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-10-08
  • 1970-01-01
  • 2019-10-10
  • 1970-01-01
  • 2011-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多