0

I want to have a strike through design before and after of my Text in TextView

----------------------- SETTINGS ---------------------

We can design this through CSS but how to design this type of TEXT in android?

Konrad Krakowiak
  • 12,067
  • 10
  • 57
  • 45
Parth Sharma
  • 349
  • 1
  • 4
  • 21

1 Answers1

0

Try this if you want strike through for the entire TextView.

TextView someTextView = (TextView) findViewById(R.id.some_text_view);
someTextView.setText(someString);
someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

If you want only a part of text, or text after and before the actual text to have a strike through try this,

TextView someTextView = (TextView) findViewById(R.id.some_text_view);
someTextView.setText(text, TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable) someTextView.getText();
spannable.setSpan(new StrikethroughSpan(), 3, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

Here text is the text which we want out TextView to display, 3 is the number of characters (starting from 0) from where the strikethrough will start.

See this SO thread.

Community
  • 1
  • 1
K Neeraj Lal
  • 6,700
  • 3
  • 22
  • 33