안녕하세요이
public void loadFont() {
font = FontFactory.createStroke(activity.getFontManager(), activity.getTextureManager(), 256, 256, Typeface.create(Typeface.createFromAsset(activity.getAssets(), "fonts/CUSTOMFONTNAME.ttf"), Typeface.BOLD), 50,
true, Color.TRANSPARENT_ABGR_PACKED_INT, 2, Color.BLACK_ABGR_PACKED_INT);
font.load();}
같은 해주세요 AndEngine - GLES2-AnchorCenter을 사용하고 있습니다 * 내 블로그 http://upadhyayjiteshandroid.blogspot.in/2012/12/android-customfont.html을 방문하여 이런 식으로하십시오.
다음과 같이
Programaticaaly 당신이 당신은 등 각 텍스트 뷰, 버튼, 대한 서브 클래스를 생성하고 생성자에서 사용자 지정 글꼴을 적용 할 수 있습니다, 수행 할 수 있습니다
public class BrandTextView extends TextView {
public BrandTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public BrandTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BrandTextView(Context context) {
super(context);
}
public void setTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/YourCustomFont_Bold.ttf"));
} else {
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/YourCustomFont.ttf"));
}
}
}
그럼 그냥 대신에 표준 것들의 사용자 정의보기를 사용 (즉, TextView 대신 BrandTextView).
<com.your.package.BrandTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View with custom font"/>
<com.your.package.BrandTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="View with custom font and bold typeface"/>
사용이 모든 당신의 main.xml에와 당신은뿐만 아니라
FontHelper.applyFont(context, findViewById(R.id.activity_root), "fonts/YourCustomFont.ttf");
where applyFont method acn be written as follows
public static void applyFont(final Context context, final View root, final String fontName) {
try {
if (root instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) root;
for (int i = 0; i < viewGroup.getChildCount(); i++)
applyFont(context, viewGroup.getChildAt(i), fontName);
} else if (root instanceof TextView)
((TextView) root).setTypeface(Typeface.createFromAsset(context.getAssets(), fontName));
} catch (Exception e) {
Log.e(TAG, String.format("Error occured when trying to apply %s font for %s view", fontName, root));
e.printStackTrace();
}
}
더 나은 이해를 위해 방문을 다음과 같이 또 다른 가능한 방법이 될 수
그들에게 사용할 수 있습니다 http://vision-apps.blogspot.in/2012/02/android-better-way-to-apply-custom-font.html
답변의 일부가 vision-apps.blogspot.com/2012/02/android-better-way-to-apply-custom-font.html에서 직접 복사 된 것으로 보입니다. 다른 사람의 작업을 사용할 때 저작자 표시를 추가하십시오. . – laalto
예, 확실한 laalto, 나는 이것을하고 있습니다 !! –
@laalto 나는 속성과 링크를 추가했다. http://upadhyayjiteshandroid.blogspot.in/2012/12/android-customfont.html은 내 자신의 블로그이기도하다. –