android - 通过多行 TextView 删除

标签 android xml android-layout

<分区>

这不是一个重复的问题,我发现了一些问题,但他们没有满意的答案,多行 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" 

    />

enter image description here

再次感谢。

最佳答案

    <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"

关于android - 通过多行 TextView 删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34262160/

相关文章:

java - Android内存管理: Engine as Singleton?

java - 如何为可绘制的线条形状制作圆角破折号或圆点

android - 具有相同设计的延伸微调器

android - 如何制作实现可点击的自定义 RelativeLayout?

android - 从数据库中检索数据并在 android 中使用 MPAndroidChart 在条形图中显示它们

java - 如何在弹出消息中找到用户名和密码时在移动应用程序中找到检查元素

java - 使用 Apache Digester 从 xml 中读取数据

xml - 如何通过前缀获取xml文件的命名空间(groovy)

html - 关闭斜线之前的空间?

android - 底部带有相机按钮的 ImageView