2013-11-22 5 views
2

문자열 변수에 설정할 사용자 정의 글꼴 BebasNeue.otf이 있습니다. 나는 많은 것을 찾았지만 어떤 해결책도 얻지 못했습니다.문자열에 사용자 지정 글꼴 설정

textView.setTypeface(font);과 같은보기에서 맞춤 글꼴을 설정할 수 있다는 것을 알고 있습니다. 하지만 지금은 내가 아래있는 Strings에 글꼴을 설정하려면 :

String Name,Contact; 
Name="ABCD"; 
Contact="97696538"; 

이 모든 문자열이 어떤 값이 들어 있습니다. 지금은 아래에있는 모든 문자열에 사용자 지정 글꼴을 설정하려면 : 내 문자열 변수에 위의 글꼴을 설정하는 방법

Typeface fontString = Typeface.createFromAsset(m_context.getAssets(), 
      "BebasNeue.otf"); 

어느 한 날을 알 수 있습니다.

도움이 될 것입니다.

감사합니다.

+0

안녕과 같이 사용할 ?? – ASP

+0

캔버스에 그림을 그릴 때이 문자열을 표시하고 있습니다. – GrIsHu

+1

도움이 될 수도 있습니다 :: http : //stackoverflow.com/questions/6042977/android-set-custom-font-to-a-paint – ASP

답변

2

아래와 같은 내용으로 @ASP 님이 제공 한 의견을 통해 문제를 해결했습니다.

Typeface fontString = Typeface.createFromAsset(m_context.getAssets(), 
       "BebasNeue.otf"); 
    Paint paint = new Paint(); 
    paint.setTypeface(fontString); 
    mCanvas.drawText("ID :" + m_sId, dw - 450, dh - 350, paint); 

저를 도와 주셔서 감사합니다.

0

아마도 도움이 될 수 있습니다.

public class TypefaceSpan extends MetricAffectingSpan { 
/** An <code>LruCache</code> for previously loaded typefaces. */ 
private static LruCache<String, Typeface> sTypefaceCache = new LruCache<String, Typeface>(
     12); 

private Typeface mTypeface; 

/** 
* Load the {@link Typeface} and apply to a {@link Spannable}. 
*/ 
public TypefaceSpan(Context context, String typefaceName) { 
    mTypeface = sTypefaceCache.get(typefaceName); 

    if (mTypeface == null) { 
     mTypeface = Typeface.createFromAsset(context.getApplicationContext().getAssets(), 
              String.format("%s", typefaceName)); 

     // Cache the loaded Typeface 
     sTypefaceCache.put(typefaceName, mTypeface); 
    } 
} 

@Override 
public void updateMeasureState(TextPaint p) { 
    p.setTypeface(mTypeface); 

    // Note: This flag is required for proper typeface rendering 
    p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); 
} 

@Override 
public void updateDrawState(TextPaint tp) { 
    tp.setTypeface(mTypeface); 

    // Note: This flag is required for proper typeface rendering 
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); 
} 
} 

그리고 u는 이러한 문자열을 표시 할 할이

SpannableString s = new SpannableString("My Title"); 
s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(), 
     Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
관련 문제