ontes personalizadas e visualização de texto personalizada no Andro

De um aplicativo que preciso desenvolver, recebi uma fonte específica que possui muitos arquivos, como FontName-Regular, FontName-Bold, FontName-it. Eu preciso usá-lo em todas as visualizações de texto no aplicativo. Primeiro, pensei que era uma tarefa fácil. Observe o SO e encontrou um tópico muito bom:aqu

Então, primeiro eu gostei:

public static void overrideFonts(final Context context, final View v) {
    try {
        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(FONT_REGULAR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // ignore
    }
}

E chamou esse método durante onCreate na minha atividade. Cada textView no meu aplicativo mostrava a fonte e o garoto, fiquei feliz por me afastar tão facilmente. Até chegar a uma tela em que algumas visualizações de texto exigiamNegrit ComoStyle (android:textStyle="bold"). Então percebi que essa solução não me oferece a possibilidade de carregar oNegrit .ttf de ativos.

@ olhou mais longe e viu uma boa implementação personalizada do TextView, na mesma pergunta SO:

public class MyTextView extends TextView {

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyTextView(Context context) {
        super(context);
        init();
    }

    public void init() {

        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
        setTypeface(tf ,1);

    }
    }

Isso parece ainda melhor. Minha pergunta é: como posso detectar noinit() se meu controle tiver Estilo definido como Negrito ou não, para que eu possa atribuir o TypeFace solicitado?

Obrigado pelo seu tempo.

LE. Seguindo o exemplo abaixo, atualizei minha turma como:

public class MyTextView extends TextView {

    Typeface normalTypeface = Typeface.createFromAsset(getContext().getAssets(), Constants.FONT_REGULAR);
    Typeface boldTypeface = Typeface.createFromAsset(getContext().getAssets(),  Constants.FONT_BOLD);

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextView(Context context) {
        super(context);
    }

    public void setTypeface(Typeface tf, int style) {
        if (style == Typeface.BOLD) {
            super.setTypeface(boldTypeface/*, -1*/);
        } else {
            super.setTypeface(normalTypeface/*, -1*/);
        }
    }
}

Bem, se eu depurar, o aplicativo entra em setTypeFace e parece aplicar o negrito, mas no meu layout não vejo nenhuma alteração, não negrito. Independentemente da fonte usada, nenhuma alteração é feita no meu TextView e é exibida com a fonte padrão do Android. Eu quero saber porque

Resumi tudo em uma postagem no blogaqui no meu blog talvez ajude alguém.

questionAnswers(6)

yourAnswerToTheQuestion