Android: Strike-through a TextView


There are many scenarios in which we need to show a Strike-through text to an android user like Old prices, old offers, etc. But android doesn’t give any such option via XML file. If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint.STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text.

But when you need it in your XML. As I am using Data Binding so my priority is to set everything related to a view in the xml. So I found this workaround on stackoverflow for my problem.

We just have to set a background that contains a line to our TextView like I did.

and the drawable for the strike-through line

and you will get the text as you want.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Roman Brazhnikov
    Thank you so much! You really saved my time 🙂
    • aastha gupta
      @romanbrazhnikov:disqus Pleasure is all mine. Good to hear that it helped you.
  • Ng Chin Shu
    Thank you! Useful information!
    Woow This is great buddy
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home