Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strike through Multiline TextView [duplicate]

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" 

    />

enter image description here

Thanks again.

like image 382
Androider Avatar asked May 17 '26 20:05

Androider


2 Answers

    <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"
like image 186
Bhargav Thanki Avatar answered May 20 '26 08:05

Bhargav Thanki


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>
like image 21
Ravi Avatar answered May 20 '26 09:05

Ravi