public final class Fonts
extends java.lang.Object
fonts.xml
):
<resources> <string name="font_arial_regular">fonts/Arial-Regular.ttf</string> <string name="font_arial_bold">font:path/to/font/Arial-Bold.ttf</string> </resources>Note: this class will only use fonts under
fonts/
directory and fonts
starting with font:
prefix.
Now you can use custom fonts in your XML layouts using android:tag
attribute:
<TextView ... android:tag="@string/font_arial_regular" />And last step you should call one of
Fonts.apply(...)
methods:
apply(android.app.Activity)
apply(android.view.View)
apply(android.widget.TextView, int)
apply(android.widget.TextView, String)
Modifier and Type | Method and Description |
---|---|
static void |
apply(android.app.Activity activity)
Applies fonts to all TextView views in Activity's window decor view.
TextView tag will be used to determine font. |
static void |
apply(android.widget.TextView textView,
int fontStringId)
Applies font to provided TextView.
Note: this class will only accept fonts under fonts/ directory
and fonts starting with font: prefix. |
static void |
apply(android.widget.TextView textView,
java.lang.String fontPath)
Applies font to provided TextView.
Note: this class will only accept fonts under fonts/ directory
and fonts starting with font: prefix. |
static void |
apply(android.view.View view)
If view is instance of ViewGroup then applies fonts to all TextView views in given
ViewGroup.
If view is instance of TextView then applies font to provided TextView. TextView tag will be used to determine the font. |
public static void apply(android.app.Activity activity)
public static void apply(android.view.View view)
public static void apply(android.widget.TextView textView, int fontStringId)
fonts/
directory
and fonts starting with font:
prefix.public static void apply(android.widget.TextView textView, java.lang.String fontPath)
fonts/
directory
and fonts starting with font:
prefix.