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

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

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

6条回答
  •  一个人的身影
    2021-02-05 07:48

    6 Amazing Ways - Android TextView Strikethrough XML & Kotlin/Java examples

    Screenshot - Android TextView Strikethrough XML & Kotlin/java Example -

    1. Using strike element.

      strings.xml

    1. StrikeThrough Using strike

        
    
    1. Using STRIKE_THRU_TEXT_FLAG

      Kotlin

      textview2.paintFlags = textview2.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
      textview2.text = "2. StrikeThrough Using Paint Flags
      

      Java

      textview2.setPaintFlags(textview2.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG); textview2.setText("2. StrikeThrough Using Paint Flags");

    2. Using SpannableString

    Kotlin

    val content1 = "3.1 StrikeThrough Using SpannableString" val spannableString1 = SpannableString(content1) spannableString1.setSpan(StrikethroughSpan(),0,content1.length,0) textview31.text = spannableString1

    Java

    textview2.setPaintFlags(textview2.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG);
        textview2.setText("2. StrikeThrough Using Paint Flags");    `
    

提交回复
热议问题