How to install custom font in android device

前端 未结 4 879
醉酒成梦
醉酒成梦 2020-12-06 05:18

I want to install custom font which is .ttf file in android device when my application start. Actually I need to install Burmese font in my android device when I run my app

相关标签:
4条回答
  • 2020-12-06 05:49

    if you have custom font then use following code:::

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

    also place your font in assets/fonts folder

    0 讨论(0)
  • 2020-12-06 06:08

    I created a FontWrapper Class for my project.

    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;
        }
    
    0 讨论(0)
  • 2020-12-06 06:11

    See here @CommonsWare answer, You cannot add fonts to an existing device, except as part of a custom firmware build, or possibly by rooting the device.

    but you can add fonts in your appliction. like:

     TextView txtvw=(TextView)findViewById(R.id.textviewname);
    
     Typeface typface=Typeface.createFromAsset(getAssets(),"fonts/burmese.ttf");
    
      txtvw.setTypeface(typface);
    

    Note: put your font in assets/fonts dir in project

    OR if your device is rooted then see this tuts for installing Custom Fonts on Your Android Device

    0 讨论(0)
  • 2020-12-06 06:13

    you need to be on root of the device

    for that you can use this application EasyRoot.apk

    Download and install ES File Explorer (https://market.android.com/details?id=com.estrongs.android.pop)

    After that you need to enable root explorer. More info can obtained from this link

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

    save fonts on your device’s /system/font folder

    More info can obtained from this link

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

    0 讨论(0)
提交回复
热议问题