당신은 XML에서 그것을 포함 할 수 없습니다/자산입니다. 당신과 같이 코드를 통해 그것을 할 수 있습니다
final TextView myTextView = getTextView();
final AssetManager assets = ctx.getAssets();
final Typeface font = Typeface.createFromAsset(assets, "thamoa.ttf");
setTypeface(font);
하나의 멋진 트릭 텍스트 뷰를 확장하고 런타임에 글꼴을 자동으로 적용하는 것입니다.
public class CustomTextView extends TextView {
public CustomTextView(Context ctx) {
super(ctx);
setupText(ctx);
}
public CustomTextView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
setupText(ctx);
}
public CustomTextView(Context ctx, AttributeSet attrs, int defStyle) {
super(ctx, attrs, defStyle);
setupText(ctx);
}
private void setupText(Context ctx) {
// check if in edit mode and return. Fonts can't be applied when viewing from editor
if(isInEditMode()) {
return;
}
final AssetManager assets = ctx.getAssets();
final TypeFace font = Typeface.createFromAsset(assets, "thamoa.ttf");
setTypeface(font);
}
}
그런 다음 당신은 같은 방법을 사용하지만, XML에과 같이 참조 할 수 있습니다 :
<package.containing.class.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!-- whatever attributes that would normally apply here -->
/>
아니요. 그렇게 할 수 없습니다. 기본 안드로이드 글꼴 만 설정할 수 있습니다. – Ahmad
어떻게 이것이 새로운 글꼴을 적용합니까? thanks –