I want to make an app in a non English language. So I need the textviews, strings and the toast to be in the non-English language. Setting the typeface for every text is cumbersome. Is there a way to set a default font? When I have to refer to something in English (like email id) then I can use the textview.settypeface(xyz) method.
There is a grate library for custom fonts in android: custom fonts
Here is a sample how to use it.
In gradle you need to put this line:
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
Then make a class that extends application and write this code:
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("your font path")
.setFontAttrId(R.attr.fontPath)
.build()
);
}
}
In the activity class put this method before onCreate:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
In your manifest file write like this:
<application
android:name=".App"
It will change the whole activity to your font!. I'ts simple solution and clean!