2

Hi I want to set Roboto font for my entire app. But only 1 text in login screen should be Arial font. Is it possible? Then how? I tried many solutions. But none of them was effective. Please help me.

andro-girl
  • 7,989
  • 22
  • 71
  • 94

1 Answers1

0

Its working for me and I hope it will help you as well Just make a single class for Roboto font and instead of TextView use the package name followed by the class name in your XML and put the Roboto font in the assest folder. for example

package com.abc.utils;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
/**
 * this class is used for set textview font.
 * @author abc
 *
 */
public class TextViewRoboto extends TextView{
    Context context;

    String TAG = getClass().getName();
    public TextViewEuro(Context context, AttributeSet attrs) { 
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {
        Typeface font = Typeface.createFromAsset(context.getAssets(), "yourrobotofontfile.ttf");

        setTypeface(font);
    }

    @Override
    public void setTypeface(Typeface tf) {
        super.setTypeface(tf);
    }

}

and now in your xml

<com.abc.utils.TextViewRoboto 
                    android:id="@+id/txt_ItemName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#EAA55A"
                    android:textSize="22sp" />

and for 1 text in login screen you can use Arial font with the help of arial font file in your asset folder

TextView tv;
Typeface tfArial = Typeface.createFromAsset(getAssets(), "arial.ttf");
// find the textview id from layout or create dynamically
tv.setTypeface(tfArial);
Hanish Sharma
  • 869
  • 8
  • 23
  • i want to change font for every controls not only textviews..and it is not gud idea to replace my textviews with this custom one..bcz my application is kind of big one.. – andro-girl Mar 02 '15 at 13:41