This in not a duplicate question, i found some question but they were not having satisfied answers, answers were not available for multiline textviews.
I have already checked this below link but they were not enough useful: Is there an easy way to strike through text in an app widget?
I want to create a line across the center of a TextView (striked TextView), but I want to do it in XML layout, not in the Java code.
I have already achieved this result through the use of JAVA code as such:
myTextView.setPaintFlags(myTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
I would like the same result, but in the below XML code:
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

Thanks again.
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="XYZ"
android:background="@drawable/line"/>
line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp"
android:color="@android:color/white"/>
</shape>
Try this !
EDIT
The above code will work only for single line text. For Multi line text use below code :
<string name="strike_text">
<strike>sample TextView \nSecond line of TextView</strike>
</string>
And use it as
android:text="@string/strike_text"
Easiest way would be to use an image.
create image with horizontal line and transparent background and set it as background of TextView
android:background="@drawable/strike_through"
Or
Create an xml file which will draw a line and set it as background of your TextView
<shape android:shape="line">
<stroke android:width="2dp" android:color="#ffffff" />
</shape>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With