I know ho to set custom font programmatically inside Android app. Is there any way to load typeface for custom font (assets) and Android framework will use proper file based on bold, italic and so on?
For example now I'm trying to set Roboto font to some TextView
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto/Roboto-Regular.ttf");
textView.setTypeface(typeface);
It works ok. But since I set TextView
inside xml layout to bold , text is not bolded
<TextView
android:id="@+id/my_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:textStyle="bold"
android:gravity="center"
android:text="@string/my_text"
android:textColor="@color/my_foreground"
android:textSize="24dp" />
How to load typeface from assets properly that this will work?
textView.setTypeface(typeface, Typeface.BOLD);
Inside my assets dir there is only one "font family"
Roboto-Black.ttf
Roboto-BlackItalic.ttf
Roboto-Bold.ttf
Roboto-BoldCondensed.ttf
Roboto-BoldCondensedItalic.ttf
Roboto-BoldItalic.ttf
Roboto-Condensed.ttf
Roboto-CondensedItalic.ttf
Roboto-Italic.ttf
Roboto-Light.ttf
Roboto-LightItalic.ttf
Roboto-Medium.ttf
Roboto-MediumItalic.ttf
Roboto-Regular.ttf
Roboto-Thin.ttf
Roboto-ThinItalic.ttf
How to load all that fonts inside one typeface/family?
"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."
No, the font properties cannot be changed. There are currently no plans to support custom fonts or sizes. MAX Agent is implemented using the Roboto font which was selected specifically for being readable at small font sizes.
Not sure if it's a good idea to post a link, but anyway... Here is my blog post on this topic, it has a class that solves this problem fully. http://anton.averin.pro/2012/09/12/how-to-use-android-roboto-font-in-honeycomb-and-earlier-versions/
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