カスタムフォントを設定し、アプリケーション全体のhtmlテキストを設定するカスタムテキストビューを作成しました。私のアプリは多くの場所で両方の機能を備えているためです。この場合、カスタム フォントを Android アプリケーション全体に設定することができます。カスタムテキストビューにhtmlテキストを適用できませんでした。
私が持っている制限:
- テキストビューを取得して使用したくありません
setText(Html.fromHtml("Some text"))
。これをコードで使用すると機能しますが、テキストを次のように使用しstrings.xml
たい<string name="my_app"><![CDATA[My Whole <b>app</b>lication]]></string>
- 最終メソッドであるため、カスタム クラス関数で settext をオーバーライドできません。
- 私は 100 近くの html テキストを持っています。この文字列をコードにハードコーディングしたくありません。助けてください。
私のカスタムクラス:
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public void setTypeface(Typeface tf) {
// TODO Auto-generated method stub
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/gothic.ttf"));
}
}
私のレイアウトファイル:
<com.views.CustomTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/my_app" />
私は出力を次のように取得します:私のアプリケーション
次のように出力したい: My app lication
太字のアプリ
これを達成する方法はありますか?