2012-06-27 5 views
1

내가 응용 프로그램의 글꼴을 변경하려면 내가 할 수 없습니다 :지정 서체 오류

의 AndroidManifest.xml을

... 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/CustomTheme" 
     > 
... 

.... 

    <style name="CustomTheme"> 
     <item name="android:typeface">stheiti.ttf</item> 
    </style> 
.... 

하지만 오류가 발생 style.xml :

error: Error: String types not allowed (at 'android:typeface' with value 'stheiti.ttf').

하지만 rootAPP/assets/stheiti가 있습니다. 그 오류가 발생, 나는 많은 사이트에서 솔루션을 검색하는 이유

.TTF 이해가 안하지만 난

감사합니다 사전에 같은 문제를 가진 하나를 찾을 수 없습니다! =)

+0

손님의 텍스트 뷰에 대해 다음과 같이 ?? – rajpara

+0

내가 아는 유일한 해결책은 여기의 해결책입니다. 앱 전체를 적용 할 방법이 없습니다. ( – RomRuben

답변

1

당신은 당신이 다음 사용자 정의보기를 만들 수 있습니다 전체 응용 프로그램에서 사용자 지정 글꼴을 구현하려면

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

처럼 텍스트보기사용자 정의 글꼴를 설정하고 글꼴을 설정할 수 있습니다 그보기의 초기화시.

public class MyTextView extends TextView { 

public MyTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init(); 
} 

public MyTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    init(); 
} 

public MyTextView(Context context) { 
    super(context); 
    init(); 
} 

public void init() { 

    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "stheiti.ttf"); 
    setTypeface(tf ,1); 

} 
0
당신은이 작업을 수행 할 수

, 당신이 (예를 설정할 수 있지만, XML을 통해 비록 당신이 설정할 수 없습니다 사용자 지정 서체 만 내장 서체) 프로그래밍 방식으로 모든보기에 사용자 지정 글꼴 설정해야

다음을 확인하십시오 : Adding custom Font to Theme in AndroidUsing a custom typeface in Android

0

아래 코드를 사용하면 도움이 될 수 있습니다. 각각 다음과 같이하고 있다는 점에서 자산에 글꼴을의 이름을 지정하여 첫 번째 메이크업 폴더로 이동하기 전에 XML의 모든 텍스트 뷰 폴더가 하시다면 글꼴을 추가 글꼴로 u는 u는 우리가 할 수있는 손님의 텍스트 뷰를 만들 필요가 전체 응용 프로그램에 대한

// Font path 
String fontPath = "fonts/trbuc.ttf"; 

// text view label 
TextView txtGhost = (TextView) findViewById(R.id.mTxtViewCustomFont); 

// Loading Font Face 
Typeface tf = Typeface.createFromAsset(mContext.getAssets(), fontPath); 

// Applying font 
txtGhost.setTypeface(tf); 
0

이 U 정상적인 텍스트 뷰

대한 동일 필요한 텍스트 뷰의 다른 특성을 추가하는 것처럼 각각의 U는 XML에서 UR 텍스트 뷰보다 폰트의 종류하려는 XML의 모든 텍스트 뷰에 대한 그 후 stheiti.ttf

import android.content.Context; 
import android.graphics.Typeface; 
import android.util.AttributeSet; 
import android.widget.TextView; 

public class MyTextView extends TextView{ 

public MyTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     init(); 

    } 

    public MyTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 

    } 

    public MyTextView(Context context) { 
     super(context); 
     init(); 

    } 



    private void init() { 
     if (!isInEditMode()) { 
      Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/stheiti.ttf"); 
      setTypeface(tf); 
     } 
    } 


} 

같아야

및 활동에 사용

<YourProjectPackageName.MyTextView 
    android:id="@+id/textview1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="22px" 
    android:textColor="#34A4c5" 
></YourProjectPackageName> 
당신이 어떤 해결책을 찾았나요

MyTextView textview=(MyTextView)findViewById(R.id.textview);