这不是一个重复的问题,我发现了一些问题,但他们没有满意的答案,多行 TextView 没有答案。
我已经检查了下面的链接,但它们不够有用:
Is there an easy way to strike through text in an app widget?
我想在 TextView
的中心创建一条线(划线 TextView
),但我想在 XML 布局中进行,而不是在 Java 代码中进行。
我已经通过使用 JAVA 代码实现了这样的结果:
myTextView.setPaintFlags(myTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
我想要相同的结果,但在下面的 XML 代码中:
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
再次感谢。
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="XYZ"
android:background="@drawable/line"/>
line.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp"
android:color="@android:color/white"/>
</shape>
试试这个!
编辑
以上代码仅适用于单行文本。
对于多行文本,请使用以下代码:
<string name="strike_text">
<strike>sample TextView \nSecond line of TextView</strike>
</string>
并将其用作
android:text="@string/strike_text"