I want to use Font Awesome\'s icon set in my android application. I have some TextView to set those icons. I don\'t want to use any png image. My Textview is li
Similar code, But small change.
Use AppCompatTextView, because when you using TextView, you will get a warning like this:
This custom view should extend android.support.v7.widget.AppCompatTextView instead
So kindly use AppCompatTextView. It will be better if you use AppCompatTextView instead of TextView:
import android.graphics.Typeface;
import android.support.v7.widget.AppCompatTextView;
import android.content.Context;
import android.util.AttributeSet;
public class FontAwesome extends AppCompatTextView{
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);
}
}