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.
Asked
Active
Viewed 726 times
2
-
Since ICS on, Roboto is the standard font on Android devices. So, you only have to change the TextView you want in Arial. I guess you know how to do that. – Phantômaxx Mar 02 '15 at 10:58
-
But the issue is if i am not setting the font as roboto explicitly if the user's device font is something else, my app is also using that font – andro-girl Mar 02 '15 at 11:02
-
If the user doesn't want to see the Roboto font... should you force him/her? – Phantômaxx Mar 02 '15 at 11:05
-
yeah..our requirement is like that – andro-girl Mar 02 '15 at 11:06
1 Answers
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