You can do this in three ways, by either setting foreground in TextView
or setting PaintFlag
or declaring a string as <strike>your_string</strike>
in strings.xml
. For example,
Through PaintFlag
This is the simplest method you just have to set strikethrough flag on your TextView as,
yourTextView.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
it will strike through your TextView.
Through foreground drawable(Works only for API 23+)
If your minSdkVersion is API version 23 +, then you can strike through your TextView by setting a foreground as,
<?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>
Now, you just have to set above drawable in your TextView as foreground
. For example,
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Textview with StrikeThrough"
android:foreground="@drawable/strikethrough_foreground" /> <!-- this is available above --!>
Through strings.xml
In this method, you have to declare your string in strings.xml
as strike through as,
<string name="strike_line"> <strike>This line is strike throughed</strike></string>
Note
But I recommend you to strike through your TextView by setting foreground drawable. Because through drawable you can easily set your strike-through line color(as like I set as red color in above example) or size or any other style property. While in the other two methods default text color is strikethrough color.