I want to make an app in a non English language. So I need the textviews, strings and the toast to be in the non-English language. Setting the typeface for every text is cumbersome. Is there a way to set a default font? When I have to refer to something in English (like email id) then I can use the textview.settypeface(xyz) method.
Change Your Font Style in Android Settings As an example, on Samsung Galaxy devices the default pathway is Settings > Display > Font and screen zoom > Font Style. Afterward, you can tap to select a font, see the immediate change, and select Apply to confirm your new selection.
"Roboto and Noto are the standard typefaces on Android and Chrome." From Wiki, "Roboto is a sans-serif typeface family developed by Google as the system font for its mobile operating system Android."
Go to Format > Font > Font. + D to open the Font dialog box. Select the font and size you want to use. Select Default, and then select Yes.
There is a grate library for custom fonts in android: custom fonts
Here is a sample how to use it.
In gradle you need to put this line:
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
Then make a class that extends application and write this code:
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("your font path")
.setFontAttrId(R.attr.fontPath)
.build()
);
}
}
In the activity class put this method before onCreate:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
In your manifest file write like this:
<application
android:name=".App"
It will change the whole activity to your font!. I'ts simple solution and clean!
You can achieve this in mainly 3 ways. one way would be to create a custom TextView and refer that everywhere, ie :
public class TypefacedTextView extends TextView {
public TypefacedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);
setTypeface(typeface);
}
}
and inside View.xml
<packagename.TypefacedTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello"/>
Another way, is to use the powerful Calligraphy
library in github. see this
And finally, you can override the defaults with your own fonts, see this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With