Waqas Ahmed Waqas Ahmed - 6 months ago 34
Java Question

creating a horizontal line over a textview in android

i am making a math tutor for school kids... In it's Subtraction lesson, I want to make a horizontal line over a textview while taking a borrow from a number.
Look at the image below. The line created on Textview.How it can be done programaticaly.. just like this.

Answer
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); 

To change hight of textView strike create drawable file strike.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"><shape android:shape="line">
    <stroke android:width="2dp" android:color="#000000" />
</shape>
</item>

in your xml set textview background

<TextView
    android:id="@+id/tv"
    android:background="@drawable/strike"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />