override View Fonts - Android Graphics

Android examples for Graphics:Font

Description

override View Fonts

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Main {
    public static void overrideFonts(final Context context, View... views) {
        try {//from   w  w w  .ja  va 2 s .  c  o m
            for (View v : views) {
                if (v instanceof ViewGroup) {
                    ViewGroup vg = (ViewGroup) v;

                    for (int i = 0; i < vg.getChildCount(); i++) {
                        View child = vg.getChildAt(i);
                        overrideFonts(context, child);
                    }

                } else if (v instanceof TextView) {
                    ((TextView) v).setTypeface(Typeface.createFromAsset(
                            context.getAssets(), "fonts/chalkboardse.ttc"));
                }
            }
        } catch (Exception e) {
        }
    }

    public static void overrideFonts(final Context context, Typeface t,
            View... views) {
        try {
            for (View v : views) {
                if (v instanceof ViewGroup) {
                    ViewGroup vg = (ViewGroup) v;

                    for (int i = 0; i < vg.getChildCount(); i++) {
                        View child = vg.getChildAt(i);
                        overrideFonts(context, child);
                    }

                } else if (v instanceof TextView) {
                    ((TextView) v).setTypeface(t);
                }
            }
        } catch (Exception e) {
        }
    }
}

Related Tutorials