0

내 응용 프로그램의 글꼴을 설정하고 싶습니다. 글꼴은 "저널"과 같습니다. 그러나 문제는 응용 프로그램에 응용 프로그램을 통합하는 방법을 모른다는 것입니다. 그리고 만약 내가 그것을 통합한다면 그것은 모든 어플리케이션을 위해 또는 선택된 어플리케이션만을위한 것일까? 왜냐하면 나는 그것을 단지 하나의 어플리케이션만을 위해 설정되기를 원하기 때문이다. 모두를위한 것이 아닙니다. 그래서 내가해야 할 일은 무엇입니까? 나는 here을 보았다. 하지만 난 그것이 TextView 및 전체 응용 프로그램 글꼴을위한 것 같아요. 그래서, 내가 매니 페스트 파일에서해야 할 일이 있습니까 ??? 또는 나는 그 밖에 무엇을해야합니까 ?? 도와주세요.안드로이드 용 글꼴을 통합하는 방법에 문제가 있습니다.

답변

2

나는 문을 @Kheldar하는 데 동의합니다. Android 앱에서 글꼴을 변경하는 방법은 없습니다. 이 코드를 사용하면 요소의 글꼴을 변경할 때마다 set 메서드를 호출하지 않아도됩니다.

public class MyTextView extends TextView { 

Context context; 
String ttfName; 

public MyTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    this.context = context; 

    for (int i = 0; i < attrs.getAttributeCount(); i++) { 
     this.ttfName = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.package.my", "ttf_name"); 

     init(); 
    } 
} 

private void init() { 
    Typeface font = Typeface.createFromAsset(context.getAssets(), ttfName); 
    setTypeface(font); 
} 

@Override 
public void setTypeface(Typeface tf) { 
    super.setTypeface(tf); 
} 

}

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:package="http://schemas.android.com/apk/res/com.package.my" 
    android:id="@+id/container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="15dp" 
     android:layout_height="15dp" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="10dp" /> 
    <com.package.my.MyTextView 
     android:id="@+id/label" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_toRightOf="@+id/icon" 
     package:ttf_name="My-font.otf" /> 
</RelativeLayout> 
+0

답장을 보내 주셔서 감사합니다. 하지만 내 PC에 글꼴 파일이 있습니다. "JOURNAL.ttf"라는 이름의 Sowhere 글꼴 파일을 넣어야합니까 ?? –

+0

자산 폴더에 넣습니다. 소문자로 이름을 지정하고 xml 파일을 파일 이름과 일치하도록 변경하십시오. – nahwarang

+0

레이아웃에 버튼이 있고 버튼 텍스트에이 글꼴을 설정하고 싶다고 가정 해 봅시다. ?? 제발 도와주세요. –

1

응용 프로그램에서 시스템 전체의 글꼴을 수정할 수 없습니다 (적어도 알고 있고 악용은 금지되어 있음).

연구 링크 : http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

+0

네 감사합니다. 다른 사람들도 도울 수있는 훌륭한 자습서입니다. –

+0

내가 원하는 도움이 거의 없다. 다음 XML 파일에서 글꼴을 설정하려면? 자습서에서 데모는 xml 파일이 아닌 java 파일의 글꼴을 설정하기위한 것입니다. –

+0

내가 글꼴을 설정하는 두 줄을 사용하고 싶지 않을 때마다해야 할 일은 무엇입니까 ??? –

관련 문제