1
public class FontTextView extends TextView {

    public FontTextView(Context context) {
        super(context);
        Typeface face = Typeface.createFromAsset(context.getAssets(),"palatino.ttf");
        this.setTypeface(face);
    }

    public FontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Typeface face = Typeface.createFromAsset(context.getAssets(),"palatino.ttf");
        this.setTypeface(face);
    }

    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        Typeface face = Typeface.createFromAsset(context.getAssets(),"palatino.ttf");
        this.setTypeface(face);
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

}

カスタムフォントを使用するために、このようなテキストビューがあります。問題は、それを正当化することです。次のようなhtmlコードを使用してみました:

testText.setText(Html.fromHtml("<html><head><div class=\"haodi_jianjie\";style=\"text-align:justify;text-justify:distribute-all-lines;color:white;background-color:black;\">asdsadsadsadsadsadsadsafsdvvbcvbcvb dfsdfsdgfgdfg  gdfghththgfhgfhgfhgfhfghgfhgfhgf sdfsdfsdfsdfsdfsdfsfwqewqewq</div></head></html>"));

しかし、うまくいきません。透明な背景は webview のバグであるため、web-view を使用しないことを好みますが、背景を透明にする必要があります。

どうもありがとう。

4

2 に答える 2

0

このための簡単なクラスを作成しました。NO WEBVIEWSUPPORTS SPANNABLES は必要ありません。独自のカスタム フォントを提供することもできます。

ライブラリ: https://github.com/bluejamesbond/TextJustify-Android

画像

于 2015-01-04T06:47:14.030 に答える