I want to install custom font which is .ttf file in android device when my application start. Actually i need to install Gujarati font in my android device when i run my application. is it possible ? if yes then how? Thanks. I don't need typeface.. i want to install in system setting without root device
Asked
Active
Viewed 2,716 times
1
-
not possible because all font related folder in root directory. and root directory can not access without root. – Bhavesh Rangani Feb 10 '16 at 06:56
-
but if You don´t include it in Your app, then nobody will have it if You release the app.....is this really that what You want? – Opiatefuchs Feb 10 '16 at 06:56
-
if you read gujarati font then you can use apps. that can translate your selected text. – Bhavesh Rangani Feb 10 '16 at 06:57
1 Answers
0
there is no other way to install font from your application without root its possible only when you put shruti.ttf file into assert folder
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/verdana.ttf");
textfield.setTypeface(tf,Typeface.BOLD);
Also you can set your font by Extending other control ex.TextView
public class TextViewWithFont extends TextView {
private int defaultDimension = 0;
private int TYPE_BOLD = 1;
private int TYPE_ITALIC = 2;
private int FONT_ARIAL = 1;
private int FONT_OPEN_SANS = 2;
private int fontType;
private int fontName;
public TextViewWithFont(Context context) {
super(context);
init(null, 0);
}
public TextViewWithFont(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
private void init(AttributeSet attrs, int defStyle) {
// Load attributes
final TypedArray a = getContext().obtainStyledAttributes(
attrs, R.styleable.font, defStyle, 0);
fontName = a.getInt(R.styleable.font_name, defaultDimension);
fontType = a.getInt(R.styleable.font_type, defaultDimension);
a.recycle();
MyApplication application = (MyApplication ) getContext().getApplicationContext();
if (fontName == FONT_ARIAL) {
setFontType(application .getArialFont());
} else if (fontName == FONT_OPEN_SANS) {
setFontType(application .getOpenSans());
}
}
private void setFontType(Typeface font) {
if (fontType == TYPE_BOLD) {
setTypeface(font, Typeface.BOLD);
} else if (fontType == TYPE_ITALIC) {
setTypeface(font, Typeface.ITALIC);
} else {
setTypeface(font);
}
}
}

Sanjay Bhalani
- 2,424
- 18
- 44
-
Shruti is a paid commercial font from Microsoft @ 800$ per Year - https://www.fonts.com/font/microsoft-corporation/shruti – appbootup Jan 11 '17 at 12:14