0

I have a list of fonts in my dropdown box and installation process would be by selecting one. I need some guidance in code how would I install this ? I have placed the ' ttf ' font files in assets/font directory. This is what I have so far.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listAssetFiles("font");
}

private boolean listAssetFiles(String path) 
{
    String [] list;
    final List<String> fontList = new ArrayList<String>();
    try {
        list = getAssets().list(path);
        if (list.length > 0) {
            for (String file : list) {
                if (!listAssetFiles(path + "/" + file))
                    return false;
                else {
                    fontList.add(file);
                    dropdown = findViewById(R.id.spinner1);
                    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, fontList);
                    dropdown.setAdapter(adapter);
                }
                dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view,
                                               int position, long id) {
                        // Get select item
                        int sid = dropdown.getSelectedItemPosition();
                        switch (position) {
                            case 0:
                                Toast.makeText(getBaseContext(), "You have selected Xacto Blade" , Toast.LENGTH_SHORT).show();
                                break;
                            case 1:
                                Toast.makeText(getBaseContext(), "You have selected Xanadu ", Toast.LENGTH_SHORT).show();
                                break;
                            case 2:
                                Toast.makeText(getBaseContext(), "You have selected Xcelsion ", Toast.LENGTH_SHORT).show();
                                break;
                            case 3:
                                Toast.makeText(getBaseContext(), "You have selected Xcelsion Italic ", Toast.LENGTH_SHORT).show();
                                break;
                        }
                    }
                    @Override
                    public void onNothingSelected(AdapterView<?> parent) {
                        // TODO Auto-generated method stub
                    }
                });
            }
        }
    } catch (IOException e) {
        return false;
    }
    return true;
}
Tony
  • 529
  • 2
  • 6
  • 24
  • "How to Install new fonts in Android?" -- what does "install" mean with respect to fonts? – CommonsWare Feb 06 '18 at 16:45
  • It's an app that can install additional fonts. – Tony Feb 06 '18 at 16:49
  • Please explain **in detail** what "install additional fonts" means, with respect to an Android app and an Android device. – CommonsWare Feb 06 '18 at 16:50
  • Lets say you're on Android Device and you're viewing text in Roman Times but you want to change font to 'Xacto Blade' which you don't have on your device, this app allows you to install this new fonts so you can use it. – Tony Feb 06 '18 at 17:15
  • These links might help you https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html https://stackoverflow.com/questions/27588965/how-to-use-custom-font-in-android-studio – Sivakumar S Feb 06 '18 at 17:22

1 Answers1

0

Lets say you're on Android Device and you're viewing text in Roman Times

The decision of what font to use is up to the developers of the app in which the user is "viewing text".

but you want to change font to 'Xacto Blade' which you don't have on your device

The user is not in control over what fonts are used by apps, outside perhaps of rooted devices and stuff like Xposed modules.

this app allows you to install this new fonts so you can use it

There is no concept in Android of installing fonts on the device. Even if you are on a rooted device, and your app copies the font somewhere onto the device, apps will not use it, because those developers do not know about this font.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • There are some apps that our users use to create content, eg. WPS, WhiteBoard. Text can be added to the document. Our users need a specific font to be available, hence why I am looking into if it is possible to add fonts to the general system as you could in Windows, Linux, Mac. I have seen font installer apps on the Play Store (e.g. FontFix, MIUI), which made me think it should be possible to install system fonts on Android. – Tony Feb 06 '18 at 17:58
  • @Tony: "Our users need a specific font to be available" -- then contact the developers of those apps and ask them to support this specific font. "I have seen font installer apps on the Play Store (e.g. FontFix, MIUI)" -- they require root, and they still do not cause apps to magically know that these fonts exist. – CommonsWare Feb 06 '18 at 18:01