package moe.yuuta.workmode.widgets; import android.content.Context; import android.content.res.TypedArray; import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.AttributeSet; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatTextView; import moe.yuuta.workmode.R; public class HtmlTextView extends AppCompatTextView { public HtmlTextView(Context context) { this(context, null); } public HtmlTextView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, android.R.attr.textViewStyle); } public HtmlTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.HtmlTextView, defStyleAttr, 0); setText(Html.fromHtml(a.getString(R.styleable.HtmlTextView_html))); if (a.getBoolean(R.styleable.HtmlTextView_enableLinks, false)) setMovementMethod(new LinkMovementMethod()); } }