Reputation: 627
I want to add some fonts on my android device. I know it must be rooted to install fonts. But some devices like galaxies (mine is Galaxy S II) support fonts without being root. I mean what's the way to add fonts on non-rooted devices (if supported)?
Is it just copying that font in the font folder or something?
thank you in advance!
I don't want to use a font in an application and just change type of a text view or something. I want to change font of my android system. For example the font of setting menu and other places of that device.
Upvotes: 0
Views: 414
Reputation: 443
If you don't want to set typeface each time. You can create a custom TextView
public class CustomFontTypeTextView extends TextView {
public CustomFontTypeTextView(Context context) {
super(context);
init(context);
}
public CustomFontTypeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
if (!isInEditMode()) {
Typeface font = Typeface.createFromAsset(context.getAssets(), "Your TypeFce");
setTypeface(font);
}
}
}
Upvotes: 0
Reputation: 3192
You you can, u can't define font into xml layouts. You need to use it dynamically each time. Check this tutorial for instance.
In case link is dead, here is a sum up of the stuff :
Get a font file like times.ttf
put it in your asset folder, inside a "fonts" folder
,Get a reference of TextView
(Ui Element) with something like that:
TextView tv = (TextView) findViewById(R.id.myCustomTVFont);
Grab you font from the asset folder:
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.ttf");
Make your TextView look great:
tv.setTypeface(tf);
Upvotes: 1