こんにちは私はこれに関する解決策を持っていますあなたはこのようにフォントを使ってみることができます...私は私のプロジェクトにこれを実装しました...
手順:
- パッケージを作成する(com.fontUtils.fonts)
- TextView
EditText
またはボタンテキストのようにフォントファイルを作成します
例えば :
public class ButtonHelveticaBold extends Button {
Context ButtonFontContext;
public ButtonHelveticaBold(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ButtonFontContext = context;
}
public ButtonHelveticaBold(Context context, AttributeSet attrs) {
super(context, attrs);
ButtonFontContext = context;
}
public ButtonHelveticaBold(Context context) {
super(context);
ButtonFontContext = context;
}
@Override
public void setTypeface(Typeface tf, int style) {
Typeface typeFaceHelvetica;
if (style == Typeface.BOLD) {
typeFaceHelvetica = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_bold_neue.ttf");
} else {
typeFaceHelvetica = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_neue_regular.ttf");
}
super.setTypeface(typeFaceHelvetica);
}
}
3:これをXMLで次のように使用します。
<com.fontUtils.fonts.ButtonHelveticaBold
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>