Change view text size. - Android User Interface

Android examples for User Interface:View

Description

Change view text size.

Demo Code


//package com.java2s;

import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;

import android.widget.TextView;

public class Main {
    /**/* www  . jav a  2 s  . c om*/
     * Change view text size.
     *
     * @param size text size, unit px.
     * @param vg   root view
     */
    private static void changeSize(float size, ViewGroup vg) {
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            changeSize(size, v);
        }
    }

    /**
     * Change view text size.
     * <p>
     * All descendant {@link android.widget.TextView} will changed the font
     * </p>
     *
     * @param size text size, unit px.
     * @param v    root view
     */
    public static void changeSize(float size, View v) {
        if (v instanceof ViewGroup) {
            changeSize(size, (ViewGroup) v);
        } else if (v instanceof TextView) {
            ((TextView) v).setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
        }
    }
}

Related Tutorials