15

我想在我的应用程序启动时在 android 设备中安装自定义字体,即 .ttf 文件。实际上,当我运行我的应用程序时,我需要在我的 android 设备中安装缅甸字体。可能吗?如果是,那么如何?我不需要字体。我想安装在系统中。

4

4 回答 4

21

请参阅 此处@CommonsWare 答案,您不能将字体添加到现有设备,除非作为自定义固件构建的一部分,或者可能通过生根设备。

但您可以在应用程序中添加字体。喜欢:

 TextView txtvw=(TextView)findViewById(R.id.textviewname);

 Typeface typface=Typeface.createFromAsset(getAssets(),"fonts/burmese.ttf");

  txtvw.setTypeface(typface);

注意:将您的字体放在assets/fonts项目的目录中

或者,如果您的设备已植根,请参阅此 tuts 以在您的 Android 设备上安装自定义字体

于 2012-04-07T05:04:04.290 回答
4

你需要在设备的根目录下

为此,您可以使用此应用程序 EasyRoot.apk

下载并安装 ES File Explorer (https://market.android.com/details?id=com.estrongs.android.pop)

之后,您需要启用根资源管理器。可以从此链接获得更多信息

http://chetangole.com/blog/2011/08/enabling-installing-hindi-marathi-unicode-fonts-on-android-mobile/

将字体保存在设备的 /system/font 文件夹中

可以从此链接获得更多信息

http://chetangole.com/blog/2011/08/enabling-installing-hindi-marathi-unicode-fonts-on-android-mobile/

于 2012-04-07T05:17:09.557 回答
3

如果您有自定义字体,请使用以下代码:::

TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/Verdana.ttf");
tv.setTypeface(face);

还将您的字体放在 assets/fonts 文件夹中

于 2012-04-07T05:01:56.517 回答
0

我为我的项目创建了一个 FontWrapper 类。

public static Typeface getTypeface(Context c, Fonts name) {

        synchronized (typefaces) {

            if (!typefaces.containsKey(name)) {

                try {
                    String fontPath = getFontsPath(name);

                    if (!StringUtil.isNullOrEmpty(fontPath)) {
                        InputStream inputStream = c.getAssets().open(fontPath);
                        File file = createFileFromInputStream(inputStream);
                        if (file == null) {
                            return Typeface.DEFAULT;
                        }
                        Typeface t = Typeface.createFromFile(file);
                        typefaces.put(name, t);
                    } else {
                        return Typeface.DEFAULT;
                    }

                } catch (Throwable e) {
                    e.printStackTrace();
                    return Typeface.DEFAULT;
                }
            }
            return typefaces.get(name);
        }
    }

private static File createFileFromInputStream(InputStream inputStream) {

        try {
            File f = File.createTempFile("font", null);
            OutputStream outputStream = new FileOutputStream(f);
            byte buffer[] = new byte[1024];
            int length = 0;

            while ((length = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, length);
            }

            outputStream.close();
            inputStream.close();
            return f;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
于 2018-04-16T04:42:39.970 回答