I am creating one Application in which I want to set custom font.
But I can't use custom Fonts in .xml file, for using this I need to initialize each and every TextView in .java file.
This process is Too much lengthy and time consuming.
If anyone know then please help me...
解决方案
For your reference,
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/yourfont.ttf");
setTypeface(tf ,1);
}
}
In XML,
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Your text"
/>