Justify text in an Android app using a WebView but presenting a TextView-like interface?

后端 未结 6 623
别那么骄傲
别那么骄傲 2020-11-29 02:27

I\'m looking for a simple way to forget that I\'m using a WebView to have justified text in my TextView. Has someone made a custom view for this? I

6条回答
  •  攒了一身酷
    2020-11-29 03:02

    I believe this simplest form. And I worked perfectly

    package domo.suichbt.util;
    
    import android.content.Context;
    import android.text.Html;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    public class JustifiedTextView extends TextView
    {
        private final String CORE_TEMPLATE = "%s";  
    
    public JustifiedTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setText(Html.fromHtml(String.format(CORE_TEMPLATE,getText())));
    }
    
    public JustifiedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setText(Html.fromHtml(String.format(CORE_TEMPLATE,getText())));
    }
    
    public JustifiedTextView(Context context) {
        super(context);
        setText(Html.fromHtml(String.format(CORE_TEMPLATE,getText())));
    }
    
    public JustifiedTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setText(Html.fromHtml(String.format(CORE_TEMPLATE,getText())));
    }
    }
    

    Insert xml example

        
    
    

提交回复
热议问题