Search code examples
androidtext

can I define middle-lined text in an Android layout xml file


How can I define middle-lined(strikethrough) text in an Android layout xml file?


Solution

  • To strike through, you can use a background image to create the strikethrough effect:

     android:background="@drawable/strike_through"
    

    Where strike_through drawable is a 9-patch image that keeps a line through the middle. This is the easiest way to implement it.

    or you can do it programatically as this.

    TextView t = (TextView) findViewById(R.id.text);
    t.setText("Text here");
    t.setPaintFlags(t.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);