Hi here is a good example.
If there are many TextViews whose external font need to be set, then you have to create a your own custom TextView and set the font like as below:
Add FontManager as a Singleton Java class
public class FontManager {
public static Typeface light;
public static Typeface medium;
public static Typeface regular;
private static FontManager instance;
private AssetManager mgr;
private FontManager(AssetManager _mgr) {
this.mgr = _mgr;
lght = Typeface.createFromAsset(mgr,"---.ttf");
medium = Typeface.createFromAsset(mgr,"---.ttf");
regular = Typeface.createFromAsset(mgr,"---.ttf");
}
public static FontManager init(AssetManager mgr) {
if(instance != null)
return instance;
return instance = new FontManager(mgr);
}
public static FontManager getInstance() {
return instance;
}
private String fixAssetFilename(String asset) {
// Empty font filename?
// Just return it. We can't help.
if (asset.length() == 0)
return asset;
return asset;
}
}
Call it in your Splash Activity as:
FontManager.init(getApplicationContext().getAssets());
public class LightTextView extends TextView {
public LightTextView(Context context) {
super(context);
}
public LightTextView(Context context, AttributeSet attrs) {
super(context, attrs);
if(context.getString(R.string.lang).equals("en"))
setTypeface(FontManager.light);
else
setTypeface(FontManager.medium);
}
}
Add values --> string.xml
<string name="lang">en</string>
values-fr --> string.xml
<string name="lang">fr</string>
<com.exa.fonttest.LightTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:textSize="20sp"
android:textColor="@color/white"
android:text="Good luck"/>
While changing the locale automatically change the font.
Good luck.