creating a strikethrough text?
Can I create a strikethrough text in Android, I mean adding a special value in the TextView
tag that can make this possible?
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#040404"
android:typeface="sans"
android:textSize="12dip"
android:textStyle="bold"/>
Paint.STRIKE_THRU_TEXT_FLAG
TextView someTextView = (TextView) findViewById(R.id.some_text_view);
someTextView.setText(someString);
someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
For painting text, there are several bit flags for doing things like bold, italics, and yes strikethrough. So to enable the strikethrough, you need to flip the bit that corresponds to this flag. The easiest way to do this is to use a bitwise-or on the current flags and a constant that corresponds to a set of flags with only the strikethrough flag enabled.
Edit from Comment by Ε Г И І И О :
For any one wanting to remove this flag, this is how:
someTextView.setPaintFlags(someTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
It is really easy if you are using strings:
<string name="line"> Not crossed <strike> crossed </strike> </string>
And then just:
<TextView
...
android:text="@string/line"
/>