Android Typeface Create setTypeface(Context context, String font, Button... buttons)

Here you can find the source of setTypeface(Context context, String font, Button... buttons)

Description

Sets a determined font on a button element view

License

Open Source License

Parameter

Parameter Description
context Context in which the TextView can be found
font Font to be set in the text view see available fonts as static attributes of this class
buttons Buttons to which the font will be applied

Declaration

public static void setTypeface(Context context, String font,
        Button... buttons) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.graphics.Typeface;

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

public class Main {
    /**//from   w  w w .  j  a va 2  s.  co  m
     * Sets a determined font on a text view element
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param style
     *    {@see Typeface}
     * @param textViews
     *    TextViews to which the font will be applied
     */
    public static void setTypeface(Context context, String font, int style,
            TextView... textViews) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        for (TextView txt : textViews) {
            txt.setTypeface(tf, style);
        }
    }

    /**
     * Sets a determined font on a text view element
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param textViews
     *    TextViews to which the font will be applied
     */
    public static void setTypeface(Context context, String font,
            TextView... textViews) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        for (TextView txt : textViews) {
            txt.setTypeface(tf);
        }
    }

    /**
     * Sets a determined font on a button element view
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param buttons
     *    Buttons to which the font will be applied
     */
    public static void setTypeface(Context context, String font,
            Button... buttons) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        for (Button txt : buttons) {
            txt.setTypeface(tf);
        }
    }

    /**
     * Sets a determined font on a text view element
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param style
     *    {@see Typeface}
     * @param buttons
     *    Buttons to which the font will be applied
     */
    public static void setTypeface(Context context, String font, int style,
            Button... buttons) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        for (Button txt : buttons) {
            txt.setTypeface(tf, style);
        }
    }

    /**
     * Sets a determined font on a text view element
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param style
     *    {@see Typeface}
     * @param group
     *    Root layout in which TextView and Buttons will be searched to apply the font
     */
    public static void setTypeface(Context context, String font, int style,
            ViewGroup group) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        int count = group.getChildCount();
        View v;
        for (int i = 0; i < count; i++) {
            v = group.getChildAt(i);
            if (v instanceof TextView)
                ((TextView) v).setTypeface(tf, style);
            else if (v instanceof ViewGroup)
                setTypeface(context, font, style, (ViewGroup) v);
        }
    }

    /**
     * Sets a determined font on a text view element
     *
     * @param context
     *    Context in which the TextView can be found
     * @param font
     *    Font to be set in the text view see available fonts as static attributes of this class
     * @param group
     *    Root layout in which TextView and Buttons will be searched to apply the font
     */
    public static void setTypeface(Context context, String font,
            ViewGroup group) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
        int count = group.getChildCount();
        View v;
        for (int i = 0; i < count; i++) {
            v = group.getChildAt(i);
            if (v instanceof TextView)
                ((TextView) v).setTypeface(tf);
            else if (v instanceof ViewGroup)
                setTypeface(context, font, (ViewGroup) v);
        }
    }
}

Related

  1. setTypeface(Context context, String font, int style, TextView... textViews)
  2. setTypeface(Context context, String font, TextView... textViews)
  3. setTypeface(Context context, String font, int style, Button... buttons)
  4. setTypeface(Context context, String font, int style, ViewGroup group)
  5. setTypeface(Context context, String font, ViewGroup group)
  6. getTypeface(Activity activity)