2012-11-26 2 views
0

내 안드로이드 응용 프로그램에 외부 글꼴 영향을 사용하고 싶습니다. 현재 내 글꼴을 사용할 수있게 해주는 코드는 다음과 같습니다.내 Android 용 Impact와 같은 외부 글꼴을 사용하려면 어떻게해야하나요?

Paint textPaint = new Paint(); 
    textPaint.setAntiAlias(true); 
    textPaint.setTextSize(FONT_SIZE); 
    textPaint.setColor(0xFFFFFFFF); 
    Log.i(TAG, "- Paint: " + textPaint); 

    Typeface face = textPaint.getTypeface(); 
    Log.i(TAG, "- default typeface: " + face); 

    face = Typeface.DEFAULT_BOLD; 
    Log.i(TAG, "- new face: " + face); 
    textPaint.setTypeface(face); 

하지만 사용하려는 글꼴의 일반 버전이 잘못되었습니다. Impact 글꼴에 익숙하지 않은 사용자를 위해 밈 글꼴을 만들 수있는 글꼴입니다. DEFAULT_BOLD 대신 Impact 글꼴을 사용하려면 무엇을해야하는지 알고 있습니까?

답변

2

사용 canvas 텍스트 그릴,

Typeface mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/samplefont.ttf"); 
Paint mPaint = new Paint(); 
mPaint.setTypeface(mFace); 
canvas.drawText("Default", 10, 100, mPaint); 

TextView이 작업을 수행 할 setTypeface 방법을 사용할 수 있습니다;

+0

이 파일을 추가하려면 pswwei의 예에서'res/assets' 디렉토리의 글꼴 파일을'fonts /'하위 디렉토리에 있어야합니다. 배급을하기 전에 글꼴의 라이센스가 재배포와 사용을 허용하는지 확인하십시오! – Phix

+0

와우 이것은 완벽하게 작동합니다! 'canvas.drawText'를 제거한 다음'textPaint.setTypeface (face);를'textPaint.setTypeface (mFace);로 변경했습니다. – Jack

관련 문제