You can do this in three ways, either by setting the foreground in the TextView , or by setting PaintFlag or by declaring the line as <strike>your_string</strike> in strings.xml . For example,
Via PaintFlag
This is the easiest method, you just need to set the crossed out flag in your TextView as,
yourTextView.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
it will break your TextView.
Across the foreground
You can also break through your TextView by setting the 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 need to set the above drawn 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 --!>
Via strings.xml
In this method, you should declare your string in strings.xml as through,
<string name="strike_line"> <strike>This line is strike throughed</strike></string>
The note
But I recommend that you get through your TextView by setting the foreground for drawing. Because with drawable you can easily set your hit on the color of the line (as I set as red in the example above) or on the size or any other style property. While in the other two methods, the default text color is to hit the color
Heisenberg Feb 03 '18 at 6:44 2018-02-03 06:44
source share