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

后端 未结 6 2000
借酒劲吻你
借酒劲吻你 2021-02-05 07:13

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

6条回答
  •  感动是毒
    2021-02-05 08:05

    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);
    

提交回复
热议问题