당신이 코드를 사용할 수 있습니다
Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/font.ttf");
TypefaceSpan actionBarTypeFace = new CustomTypefaceSpan("", typeface);
SpannableString s = new SpannableString("Item");
s.setSpan(actionBarTypeFace, 0, s.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
MenuItem item = menu.add(21, 66, 0, s);
item.setTitle(s);
CustomTypeFaceSpan을 :
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
public CustomTypefaceSpan(String family, Typeface type) {
super(family);
newType = type;
}
@Override
public void updateDrawState(TextPaint ds) {
applyCustomTypeFace(ds, newType);
}
@Override
public void updateMeasureState(TextPaint paint) {
applyCustomTypeFace(paint, newType);
}
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
int fake = oldStyle & ~tf.getStyle();
if ((fake & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(tf);
}
}
덕분에, 동료,이 위대하다! CustomTypefaceSpan 클래스를 제공하는 것을 잊어 버렸지 만, 인터넷의 다른 곳에서 그것을 발견하고 그것을 내 프로젝트에 배치했습니다. 가능한 한 빨리 답변을 수락하겠습니다. –
답변을 업데이트했습니다. –