Custom font
samchorge opened this issue · 0 comments
Hi Loren,
Superb code. In my project, I use custom font and use following code to apply my custom font to all controls in the layout.
public static void applyFont(final Context context, final View root, final String fontPath) {
try {
if (root instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) root;
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++)
applyFont(context, viewGroup.getChildAt(i), fontPath);
} else if (root instanceof TextView)
((TextView) root).setTypeface(Typeface.createFromAsset(context.getAssets(), fontPath));
} catch (Exception e) {
Log.e(TAG, String.format("Error occured when trying to apply %s font for %s view", fontPath, root));
e.printStackTrace();
}
}
I tried this introducing in your code but couldn't find the appropriate place. Can you pls guide me?
Thanks