setup ViewGroup Font - Android User Interface

Android examples for User Interface:ViewGroup

Description

setup ViewGroup Font

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 setupFont(Context context, ViewGroup rootView,
            String assertFont) {/*w  w  w.ja  va2 s. com*/
        Typeface tf = Typeface.createFromAsset(context.getAssets(),
                assertFont);
        setFont(rootView, tf);
    }

    private static void setFont(ViewGroup vg, Typeface tf) {
        int childCount = vg.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View view = vg.getChildAt(i);
            if (view instanceof ViewGroup) {
                setFont((ViewGroup) view, tf);
            }
            if (view instanceof TextView) {
                ((TextView) view).setTypeface(tf);
            }
        }
    }
}

Related Tutorials