カスタムフォントを実装するにはここではいくつかの例が異なりますが、私はapplication.i上で使用されている1つの抽象クラスでカスタムフォントを使用しています。ありがとうございます。 androidのtextviewでカスタムフォントを使用する方法
-1
A
答えて
1
あなたはこのように行うことができ、 http://www.androidhive.info/2012/02/android-using-external-fonts/
2
をこれを確認する詳細については、資産
// Font path
String fontPath = "fonts/Face Your Fears.ttf";
// text view label
TextView txtGhost = (TextView) findViewById(R.id.ghost);
// Loading Font Face
Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
// Applying font
txtGhost.setTypeface(tf);
フロンカスタムフォントのためにこれを試してみてください。 XMLで
public final class ArialMTBoldRegularTextView extends CustomTextView {
public static final String FONT_PATH = "arial-rounded-mt-bold.ttf";
public ArialMTBoldRegularTextView(Context context) {
super(context);
setFont(FONT_PATH);
}
public ArialMTBoldRegularTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
setFont(FONT_PATH);
}
public ArialMTBoldRegularTextView(Context context, AttributeSet attributeSet, int defStyleAttr) {
super(context, attributeSet, defStyleAttr);
setFont(FONT_PATH);
}
public void setFont(String fontPath) {
changeFont(this, fontPath);
}
public static void changeFont(final CompoundButton button, final String fontPath) {
Typeface typeface = Typeface.createFromAsset(button.getContext().getAssets(), fontPath);
button.setTypeface(typeface);
}
}
CustomTextView.java
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
}
public CustomTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public CustomTextView(Context context, AttributeSet attributeSet, int defStyleAttr) {
super(context, attributeSet, defStyleAttr);
}
public Typeface getFont(final Context context, final String fontPath) {
return Typeface.createFromAsset(context.getAssets(), fontPath);
}
public void changeFont(final TextView textView, final String fontPath) {
Typeface typeface = Typeface.createFromAsset(textView.getContext().getAssets(), fontPath);
textView.setTypeface(typeface);
}
public void changeFont(final CompoundButton button, final String fontPath) {
Typeface typeface = Typeface.createFromAsset(button.getContext().getAssets(), fontPath);
button.setTypeface(typeface);
}
}
とfater:
<packagename.views.ArialMTBoldRegularTextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:gravity="center"
android:text="Pseudo"/>
4
あなたは資産フォルダ
ArialMTBoldRegularTextView.javaにご.TFFファイルを追加する必要があります以下のようなカスタムクラスを作成します。
public class CustomTextView extends TextView {
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public CustomTextView(Context context) {
super(context);
init(null);
}
private void init(AttributeSet attrs) {
if (attrs!=null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomTextView);
String fontName = a.getString(R.styleable.CustomTextView_fontName);
if (fontName!=null) {
Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/"+fontName);
setTypeface(myTypeface);
}
a.recycle();
}
}
}
あなたのフォントをassets> fontsフォルダに追加してください。
が使用するattrs.xml
<declare-styleable name="CustomTextView">
<attr name="fontName" format="string" />
</declare-styleable>
に次のように追加します。あなたのXMLから直接フォントを使用して
<com.abc.cusomclass.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fontName="/*name of your font from assets/font folder*/"/>
1
今のAndroidサポートライブラリ26個の支持体は、詳細についてはdocを参照してください。
関連する問題
- 1. ポリマーにカスタムフォントを使用する方法
- 2. AndroidスタジオTextViewと共にバックグラウンドでCountDownTimerを使用する方法
- 3. カスタムフォントを使用するandroid xamarin
- 4. TextViewのカスタムフォントNullPointerExceptionをスローする
- 5. Androidのカスタムフォント - 簡単で安い方法
- 6. androidのカスタムフォントを使用したNullPointerException
- 7. android xmlのカスタムフォントの使い方
- 8. Android Oreo(8.0+)でデフォルトのアプリケーションフォントをカスタムフォントに設定する方法
- 9. HTMLページでカスタムフォントを使用する方法
- 10. Xamarin Cross Platformでカスタムフォントを使用する方法
- 11. RShiny Appでカスタムフォントを使用する方法
- 12. android用のJavaを使用してTextViewのスクロールビューを与える方法
- 13. 電話の隙間にカスタムフォントを使用する方法は?
- 14. WiXインストーラのUIダイアログにカスタムフォントを使用する方法は?
- 15. weasyprintでカスタムフォントを使う方法
- 16. setTextを使用してandroid textViewのテキストを連結する方法
- 17. HerokuのImageMagickでカスタムフォントを使用する
- 18. android:アプリケーション全体のカスタムフォントを設定する方法
- 19. C# - システムにインストールせずにカスタムフォントを使用する方法
- 20. Androidで指のジェスチャーでImageviewとTextViewを交換する方法
- 21. Androidで丸みのあるTextViewを作成する方法は?
- 22. Xamarin Androidでカスタムフォントを使用していますか?
- 23. シンセスタイルでカスタムフォントを設定する方法
- 24. xamarinフォームでカスタムフォントを使用
- 25. eclipseでカスタムフォントを使用するには?
- 26. CSSでカスタムフォントを使用するには?
- 27. Weeblyブログでカスタムフォントを使用する
- 28. Cordovaでカスタムフォントを使用するには?
- 29. Androidのtextviewで複数のテキストカラーを使用する[Html.fromhtml()]
- 30. android projectのカスタムフォント
https://futurestud.io/tutorials/custom-fonts-on-android-extending-textviewを確認してください – nnn