Android Font Set setAppFont(ViewGroup mContainer, Typeface mFont)

Here you can find the source of setAppFont(ViewGroup mContainer, Typeface mFont)

Description

* SETS THE ENTIRE FONT FOR THE ACTIVITY!

Parameter

Parameter Description
mContainer a parameter
mFont a parameter

Declaration


public static final void setAppFont(ViewGroup mContainer, Typeface mFont) 

Method Source Code

//package com.java2s;

import android.graphics.Typeface;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Main {
    /**/*from w w w .j  a v  a  2  s.c  o  m*/
     * **************************************************************************************
     * SETS THE ENTIRE FONT FOR THE ACTIVITY!
     * <p/>
     * mContext = AddSpellActivity.this;
     * <p/>
     * Typeface tf1 = Typeface.createFromAsset(mContext.getAssets(),
     * "fonts/KaushanScript-Regular.otf"); final ViewGroup mContainer =
     * (ViewGroup) findViewById(android.R.id.content).getRootView();
     * setAppFont(mContainer, tf2);
     *
     * @param mContainer
     * @param mFont
     * @author Dan
     */

    public static final void setAppFont(ViewGroup mContainer, Typeface mFont) {
        if (mContainer == null || mFont == null)
            return;

        final int mCount = mContainer.getChildCount();

        // Loop through all of the children.
        for (int i = 0; i < mCount; ++i) {
            final View mChild = mContainer.getChildAt(i);
            if (mChild instanceof TextView) {
                // Set the font if it is a TextView.
                ((TextView) mChild).setTypeface(mFont);
            } else if (mChild instanceof ViewGroup) {
                // Recursively attempt another ViewGroup.
                setAppFont((ViewGroup) mChild, mFont);
            }
        }
    }
}