2017-12-09 2 views
-1

사용 가능한 모든 글꼴을 나열하려고합니다. 모든 것이 android Oreo에서 잘 작동하는 것 같습니다.하지만 내 탭에서 테스트했을 때 안드로이드 팀은 ...이 기능이 API 14 이상에서 지원되는 것을 말한다android 4.4에서 로컬 글꼴 사용이 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:padding="10dp"> 
<Spinner 
    android:id="@+id/size_spinner" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

</Spinner> 

<RadioGroup 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <RadioButton 
     android:id="@+id/amatic_regular" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/amatic_font" 
     android:gravity="center" 
     android:text="Amatic" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/annie_use_your_telescope" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/annie_use_your_telescope" 
     android:gravity="center" 
     android:text="annie telescope" 
     android:textSize="25sp" /> 
    <RadioButton 
     android:id="@+id/Windsong" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/windsong" 
     android:gravity="center" 
     android:text="Windsong" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/cac_champagne" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/cac_champagne" 
     android:gravity="center" 
     android:text="Cac champangne" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/fff_tsuj" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/fff_tsuj" 
     android:gravity="center" 
     android:text="fff ttsu" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/cavier_dream_font" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/cavier_dream_font" 
     android:gravity="center" 
     android:text="Cavier Font" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/roboto_regular" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/roboto_regular" 
     android:gravity="center" 
     android:text="Robboto" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/SEASRN__" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/seasran__" 
     android:gravity="center" 
     android:text="seasrn" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/Capture_it" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/capture_it" 
     android:gravity="center" 
     android:text="capture it" 
     android:textSize="25sp" /> 

    <RadioButton 
     android:id="@+id/OpenSans-Light" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:fontFamily="@font/opensans_regular" 
     android:gravity="center" 
     android:text="OpenSans Light" 
     android:textSize="25sp" /> 

</RadioGroup> 

That's what I get in android Oreo

That's what I get in android kitkat

답변

0

폰트 리소스가 Android 4.4 이상에서 지원된다고 들었지만 잘못되었습니다.

@font 자원 Android Oreo 때까지 추가되지 않은 :

안드로이드 8.0 (API 레벨 26)는 자원으로 글꼴을 사용할 수있는 새로운 기능, XML에서 글꼴을 소개합니다. res/font/폴더에 글꼴 파일을 추가하여 글꼴을 자원으로 묶을 수 있습니다. 이 글꼴은 R 파일에 컴파일되며 Android Studio에서 자동으로 사용할 수 있습니다. 새로운 자원 유형 인 글꼴을 사용하여 글꼴 자원에 액세스 할 수 있습니다. 예를 들어, 글꼴 자원에 액세스하려면 @ font/myfont 또는 R.font.myfont를 사용하십시오.

fontFamily 속성은 이전에 추가되었지만 글꼴 리소스가있는 API 26까지 available fonts까지 제한됩니다. API 26 아래의 API에서 프로그래밍 방식으로 사용자 지정 글꼴을 설정해야합니다.

Android Nougat 이하에서는 프로그래밍 방식으로 설정해야합니다. @font 리소스는 Oreo 이상에서만 지원됩니다. 으로 설정,

Typeface quicksand = Typeface.createFromAsset(c.getAssets(), 
      "Quicksand-Bold.ttf"); 

마지막 : 물론 파일 이름으로,이를 사용하여로드 먼저 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)

:

이 같은 것을 사용하여 현재 API를 확인하실 수 있습니다

someTextview.setTypeface(quicksand); 

XML 파일에서 특성을 계속 유지할 수 있습니다. 내장 때 주어진 API 레벨에 존재하지 않는 XML 태그는 단순히 무시됩니다, 그래서 당신이 지원 라이브러리를 사용

하지 않는 한 당신은 여전히 ​​API (26)에 대한 주위를 유지하고 위의 수 있습니다. 일반적으로 AppCompat 으로 알려진 지원 라이브러리를 사용하면이 라이브러리를 사용할 수 있습니다. 인스턴스의 경우 :

<?xml version="1.0" encoding="utf-8"?> 
<font-family xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <font android:fontStyle="normal" android:fontWeight="400" android:font="@font/myfont-Regular" 
      app:fontStyle="normal" app:fontWeight="400" app:font="@font/myfont-Regular"/> 
    <font android:fontStyle="italic" android:fontWeight="400" android:font="@font/myfont-Italic" 
      app:fontStyle="italic" app:fontWeight="400" app:font="@font/myfont-Italic" /> 
</font-family> 

There's a section in the docs about it 또한 읽기 좋을 수 있습니다.

또한이 종속성이 필요합니다 (이 값을 쓰면 버전이 최신입니다.

compile "com.android.support:appcompat-v7:27.0.2" 

지원 라이브러리 등의 이유로 지원 종속성의 모음입니다,하지만 APPCOMPAT 라이브러리 이전 버전에 대한 지원 라이브러리입니다 : 나중에 사용의 경우, 지원 LIB의 최신 버전)를 조회 할 수 있습니다 호환성이며 여기에서 참조 된 것입니다

+0

"Android API 버전 14 이상을 실행하는 장치에서 XML 글꼴 글꼴 기능을 사용하려면 지원 라이브러리 26을 사용하십시오. 지원 라이브러리 사용에 대한 자세한 내용은 지원 라이브러리 섹션. " –

+0

정말 고마워요! ... 지원 라이브러리가 무엇인지 이해하려고 노력할 것입니다. –

+0

@finchfisher 지원 라이브러리 자체는'com.android.support' 패키지가있는 다양한 라이브러리의 범위입니다. 당신이 찾고있는 사람은 AppCompat입니다. – Zoe

관련 문제