Android高亮TextView

HighlightTextView

API

Android文本高亮控件,基于View实现。

特点

  • 文本高亮
  • 单词自动换行
  • 高亮词组保持在同一行显示

截图

Demo

Java:
public class MainActivity extends AppCompatActivity {
    private final static String TEXT = "";
    private final static String[] HIGHLIGHT = {};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        HighLightTextView hlTv = (HighLightTextView) findViewById(R.id.hlTv);
        hlTv.setDisplayedText(TEXT, Arrays.asList(HIGHLIGHT));
        hlTv.setDefaultColor(Color.BLACK);
        hlTv.setHighlightColor(ContextCompat.getColor(this, R.color.colorPrimary));

    }
}
XML:
<com.jy.highlighttextview.HighLightTextView
    android:id="@+id/hlTv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    app:textSize="16sp" />
Methods:
method 方法 description 描述
setDefaultColor(int color) 设置默认显示颜色
setHighlightColor(int color) 设置高亮颜色
setDisplayedText(String text, List<String> highlights) 设置显示的文本和高亮词组
setTextSize(float size) 设置字体大小
xml value:
app:defaultColor="@color/colorPrimary"
app:highlightColor="@color/colorAccent"
app:text="@string/app_name"
app:textSize="16sp"

完整请移步github-> jiyangg -> HighlightText

原文地址:https://www.cnblogs.com/jiy-for-you/p/7751281.html