Skip to content

Custom font #14

@samchorge

Description

@samchorge

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions