1.效果
2.代码:
Text oldPrice = findComponentById(ResourceTable.Id_oldPrice);
TextForm textForm = new TextForm();
textForm.setStrikethrough(true); // 设置字体删除线
// textForm.setUnderline(true); // 设置下划线
textForm.setTextSize(DisplayUtils.vp2px(this, 16)); // 设置文字大小
textForm.setTextColor(Color.GRAY.getValue()); //设置文字颜色
RichTextBuilder richTextBuilder = new RichTextBuilder(textForm);
richTextBuilder.addText(oldPrice.getText()); // 文本内容
RichText richText = richTextBuilder.build();
oldPrice.setRichText(richText);
vp2px
/**
* vp转像素
*
* @param context
* @param vp
* @return
*/
public static int vp2px(Context context, float vp) {
DisplayAttributes attributes = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes();
return (int) (attributes.densityPixels * vp);
}