If you want to set external font your application. First you create assets folder and create another folder font inside the assets folder. Put which font do you want externally set in your application.
Now , Create class named FontStyle.java.
TextView address= (TextView) findViewById(R.id.tv_address);
name.setTypeface(font_bold );Now , Create class named FontStyle.java.
Public class FontStyle { Context context; public final static String roboto_bold = "fonts/roboto_bold.ttf"; public final static String roboto_regular = "fonts/roboto_regular.ttf"; public static final String roboto_italic = "fonts/roboto_italic.ttf"; public FontStyle(Context context) { this.context = context; } public Typeface getRegularTypeface() { Typeface font_roboto_regular = Typeface.createFromAsset( context.getAssets(), roboto_regular); return font_roboto_regular; } public Typeface getBoldTypeface() { Typeface font_roboto_regular = Typeface.createFromAsset( context.getAssets(), roboto_bold); return font_roboto_regular; } public Typeface getItalicTypeface() { Typeface font_roboto_italic = Typeface.createFromAsset( context.getAssets(), roboto_italic); return font_roboto_italic; } }And finally Call this FontStyle Class of your activity class, whenever you needed to set font style of you app.
FontStyle font_style = new FontStyle(TestActivity.this); Typeface font_regular = font_style.getRegularTypeface(); Typeface font_bold = font_style.getBoldTypeface(); TextView name= (TextView) findViewById(R.id.tv_name);
0 comments
Posts a comment