2014-02-25 9 views
1

게임에 맞춤 글꼴을 설정하려고하는데 실제로 어떻게해야할지 모르겠습니다. 나는 순간에 글꼴을 선택하는 방법은이 방법 당신은 당신이 도움을 주시기 바랍니다 수있는 자산 폴더에서 글꼴을로드 할 수있는 방법을 알고 있다면 "Typeface.SANS_SERIF는"글꼴사용자 정의 글꼴 설정

입니다

public void loadFont() { 
    font = FontFactory.createStroke(activity.getFontManager(), activity.getTextureManager(), 256, 256, Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD), 50, 
      true, Color.WHITE_ABGR_PACKED_INT, 2, Color.BLACK_ABGR_PACKED_INT); 
    font.load(); 
} 

을 사용하고 있습니다 나를? 주셔서 감사합니다

* 나는이 옆에

TextView text = (TextView) findViewById(R.id.custom_font); 
    Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf"); 
    text.setTypeface(font); 

보다 텍스트보기가있는 경우

답변

0

안녕하세요이

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

+0

답변의 일부가 vision-apps.blogspot.com/2012/02/android-better-way-to-apply-custom-font.html에서 직접 복사 된 것으로 보입니다. 다른 사람의 작업을 사용할 때 저작자 표시를 추가하십시오. . – laalto

+0

예, 확실한 laalto, 나는 이것을하고 있습니다 !! –

+0

@laalto 나는 속성과 링크를 추가했다. http://upadhyayjiteshandroid.blogspot.in/2012/12/android-customfont.html은 내 자신의 블로그이기도하다. –

2

Project에 또는 yourfont.otfAssets에 추가하고 c를로드하십시오. ustom font

Typeface tf = null; 
tf = Typeface.createFromAsset(context.getAssets(), "Helvetica neue.ttf"); 
TextView text = (TextView) findViewById(R.id.yourtextview); 
tv.setTypeface(face); 
2

나는 그것을 알아 냈다. 여기 코드는

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(); 
+0

은 위대한 분이다. 보다 –

0

Andengine - GLES2에서 당신은) (onCreateResources이 방법을 글꼴 사용자 정의 사용할 수 있습니다

FontFactory.setAssetBasePath("font/"); 
    final ITexture fontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR); 

    this.mFont = FontFactory.createFromAsset(this.getFontManager(), fontTexture, activity.getAssets(), "your_font_name.ttf", 40, true, android.graphics.Color.BLACK);  
    this.mFont.load(); 

당신은 "Typeface.SANS_SERIF는"이 방법으로 폰트를 사용할 수 있습니다

this.mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL), 32); 
    this.mFont.load();