add font ttf file in your assets resource
try this below class custom text view and add custom class in your xml file
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
this.setTypeface(getTypeFace(context));
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
this.setTypeface(getTypeFace(context));
}
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.setTypeface(getTypeFace(context));
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
this.setTypeface(getTypeFace(context));
}
public Typeface getTypeFace(Context context) {
Typeface font = Typeface.createFromAsset(context.getAssets(), "your_filename.ttf");
return font;
}
}
In xml file like :
<package_name.CustomTextView
android:id="@+id/tv_downloading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/icon_close"
android:textSize="100dp"
android:textStyle="bold"
android:layout_centerInParent="true"
android:background="@color/col_white"
android:textColor="@color/colorPrimaryDark"
android:visibility="visible" />