Прежде всего, убедитесь, что вы поместили загруженный файл .ttf
в папку Asset
.
Затем создайте класс с именем FontAwesome
, который расширяет TextView
следующим образом
public class FontAwesome extends TextView {
public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public FontAwesome(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FontAwesome(Context context) {
super(context);
init();
}
private void init() {
//Font name should not contain "/".
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"fontawesome.ttf");
setTypeface(tf);
}
}
Наконец, вы создаете TextView
как следует
<PACKAGE_NAME.Fontawesome
android:id="@+id/userLogin"
android:text=" Login Now"
android:clickable="true"
android:onClick="login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Надеюсь, это поможет вам.