【发布时间】:2018-02-14 21:38:20
【问题描述】:
想要添加文本视图,它将具有黑色文本颜色和不同颜色的 Strike
使用
txtview.setPaintFlags(txtview.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
【问题讨论】:
想要添加文本视图,它将具有黑色文本颜色和不同颜色的 Strike
使用
txtview.setPaintFlags(txtview.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
【问题讨论】:
您可以通过三种方式做到这一点,通过在TextView 中设置前景,或在strings.xml 中设置PaintFlag 或将字符串声明为<strike>your_string</strike>。例如,
通过 PaintFlag
这是最简单的方法,您只需在 TextView 上设置删除线标志,
yourTextView.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
它会穿透你的 TextView。
通过前景可绘制对象
您还可以通过将背景设置为来穿透 TextView,
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@android:color/holo_red_dark"/>
</shape>
</item>
</selector>
现在,您只需在 TextView 中将上述可绘制对象设置为背景。
通过strings.xml
在这种方法中,您必须在strings.xml中将您的字符串声明为删除线,
<string name="strike_line"> <strike>This line is strike throughed</strike></string>
注意
但我建议您通过设置前景可绘制来穿透您的 TextView。因为通过drawable,您可以轻松地设置您的删除线颜色(就像我在上面的示例中设置为红色一样)或大小或任何其他样式属性。而在其他两种方法中,默认的 textcolor 是删除线颜色。
【讨论】:
background,您必须将其设置为foreground。
android:foreground。