문제

내 앱에서 외부 글꼴을 사용하고 싶습니다. 나는 새로운 추가를 시도했다 fonts 사용 AssetManager 그러나 그것은 작동하지 않았습니다. 아래는 내 코드입니다.

Typeface face;

face = Typeface.createFromAsset(getAssets(), "font.otf");

textview.setTypeface(face);

그러나 그것은 텍스트를 보여주지 않습니다 ...

이것을 도와주세요.

도움이 되었습니까?

해결책

Afaik, Android는 OpenType을 지원하지 않습니다. 대신 트루 타입 글꼴을 사용하십시오.


업데이트: 분명히 OpenType는 이제 적어도 다소 지원됩니다. 원래 지원되지 않았으므로 앱이 지원하는 Android 버전에서 글꼴을 철저히 테스트해야합니다.

다른 팁

글꼴에 쉽게 액세스하려면 코드가 이후로드 할 수있는 방식으로 응용 프로그램과 함께 묶어야합니다. 이렇게하려면 자산 직접에 글꼴 폴더를 만듭니다.

이것은 당신의 .xml 일 수 있습니다

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
    android:id="@+id/DefaultFontText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:text="Here is some text." />
<TextView
    android:id="@+id/CustomFontText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:text="Here is some text.">
    </TextView>

.java 클래스에 다음 코드를 작성하십시오

Typeface tf = Typeface.createFromAsset(getAssets(),
            "fonts/BPreplay.otf");
    TextView tv = (TextView) findViewById(R.id.CustomFontText);
    tv.setTypeface(tf);

Android는 OTF를 지원합니다 (SDK 버전은 확실하지 않지만 1.6에서 확실히 작동하지 않습니다). 타자기 OTF 글꼴을 잠시 동안 사용하고 있었지만 렌더링은 내가 사용한 TTF 버전과는 거의 정확하지 않습니다. 온라인 글꼴 변환기를 통해). 기준선은 모든 곳에 있었고 (일부 문자는 다른 글자보다 2 픽셀이 더 높았으며) HTC 산불과 같은 LDPI 전화에서는 더 큰 픽셀로 인해 문제가 크게 확대됩니다.

나는 같은 문제를 겪고 있었다. 내 글꼴은 Android에서도 작동하지 않았지만 작동하기 위해 필요했습니다. 글꼴 편집기를 사용하여 글꼴의 문자를 Font에서 Android-SRC-2_1의 Fontsampler 예제와 함께 제공되는 글꼴로 복사했습니다. 완벽하게 작동했습니다.

나는 내 방법이 지적 재산권 관점에서 의심 스러웠다는 것을 인정할 것이지만, 모든 캐릭터가 교체되었고 모든 참조가 교체 된 오래된 글꼴에 대한 모든 언급이 있으므로 원래 글꼴을 사용하지 않았다. 두 글꼴이 정의되는 방식을 '찾고'시도했지만 모든 글꼴 변수 일치가 작동하지 않습니다. 그래서 NED에서 나는 원래 글꼴의 골격을 새 글꼴의 템플릿으로 사용했습니다.

Android는 OTF 및 TTF 형식을 모두 지원하며 두 가지를 모두 경험했습니다.

tv3 = (TextView)findViewById(R.id.tv1);
    Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/TRAJANPRO-BOLD.OTF");
    tv3.setTypeface(typeFace);

이것이 제가 영어와 현지 언어 모두에 사용한 단계입니다.

Fontinator IT 지원 부스 OTF 및 TTF 글꼴을 사용하십시오

안드로이드 라이브러리는 사용자 정의 글꼴을 쉽게 사용할 수 있습니다.

https://github.com/svendvd/fontinator

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top