I am currently in the process of overhauling the font of my application to use a custom font.
I have a class such as this:
public class TextViewRobotoRegular extends TextView {
public TextViewRobotoRegular(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
setTypeface(Typefaces.get(context, "Roboto-BlackItalic"));
}
}
}
where Typefaces.get
is a method which points to a cached typeface, and if not cached, creates a new instance.
For organization sake, I was wondering if I could make several TextView classes for each font within one large class, something like this
public class TextViews {
public class RobotoRegular extends TextView {
public TextViewRobotoRegular(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
setTypeface(Typefaces.get(context, "Roboto-Thin"));
}
}
}
public class RobotoThin extends TextView {
public TextViewRobotoRegular(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
setTypeface(Typefaces.get(context, "Roboto-Thin"));
}
}
}
}
Can I make these references in the xml layout files? something like:
<com.example.appname.fontPackageName.TextViews.RobotoRegular
android:id="@+id/profileNameView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />