Asaf Pinhassi
Asaf Pinhassi

Reputation: 15573

Use different font for different languages in Android

I use a custom font for EditText fields, but the font I use has only English characters. When I type in a different language the application uses the default Android font for that language.

Is it possible to have a one font for English input and another for a different language?

To set the EditText font I do:

mFont1 = Typeface.createFromAsset(context.getAssets(), "eraslght.ttf");
textView.setTypeface(mFont1 );

Upvotes: 3

Views: 3244

Answers (2)

Protostome
Protostome

Reputation: 6019

What if you used strings.xml like the following:

mFont1 = Typeface.createFromAsset(context.getAssets(), getString(R.strings.button_font));
textView.setTypeface(mFont1 );

and in strings.xml just put the relevant path as a string...

Upvotes: 3

Marcin Fiorek
Marcin Fiorek

Reputation: 21

You can check what language is currently set in system and set different fonts for them.

mFont1 = Typeface.createFromAsset(context.getAssets(), "eraslght.ttf");
if (Locale.getDefault().getDisplayLanguage() == "en") {
    textView.setTypeface(mFont1);
} else {
    textView.setTypeface(mFont2);
}

Upvotes: 1

Related Questions