protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float x_draw = getPaddingLeft();
float y_draw = getPaddingTop() + dfPaint.getTextSize();
for (ExtendText t : extendTexts) {
Paint paint = t.isHighlight ? hlPaint : dfPaint;
float textLen = paint.measureText(t.textUnit);
if (x_draw + textLen > width) {
x_draw = getPaddingLeft();
y_draw += paint.getTextSize();
}
canvas.drawText(t.textUnit, x_draw, y_draw, paint);
x_draw += textLen;
}
}
public class MainActivity extends Activity {
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));
}
}
<com.jy.highlighttextview.HighLightTextView android:id="@+id/hlTv" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" app:textSize="16sp" />
| method 方法 | description 描述 |
|---|---|
| setDefaultColor(int color) | 设置默认显示颜色 |
| setHighlightColor(int color) | 设置高亮颜色 |
| setDisplayedText(String text, List<String> highlights) | 设置显示的文本和高亮词组 |
| setTextSize(float size) | 设置字体大小 |
app:defaultColor="@color/colorPrimary" app:highlightColor="@color/colorAccent" app:text="@string/app_name" app:textSize="16sp"
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有