android - 创建删除线文本?

标签 android user-interface

我可以在 Android 中创建一个删除线文本吗,我的意思是在 TextView 标记中添加一个特殊值可以实现这一点?

<TextView
    android:id="@+id/title" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textColor="#040404"
    android:typeface="sans" 
    android:textSize="12dip"
    android:textStyle="bold"/>

最佳答案

Paint.STRIKE_THRU_TEXT_FLAG

TextView someTextView = (TextView) findViewById(R.id.some_text_view);
someTextView.setText(someString);
someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

For painting text, there are several bit flags for doing things like bold, italics, and yes strikethrough. So to enable the strikethrough, you need to flip the bit that corresponds to this flag. The easiest way to do this is to use a bitwise-or on the current flags and a constant that corresponds to a set of flags with only the strikethrough flag enabled.

Comment 编辑由 Ε Г И І И О :

对于任何想要删除此标志的人,方法如下:

someTextView.setPaintFlags(someTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));

关于android - 创建删除线文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9786544/

相关文章:

java - 为每个元素添加一个按钮到 ListView

java - 循环不遍历整个arraylist

user-interface - gtkD:最小绘图示例?

python - $DISPLAY 设置正确吗? - 在 docker 容器中运行 wxPython Phoenix GUI

android - RemoteServiceException 在 MIUI 11 上使我的应用程序崩溃

android - 显式 Intent 、隐式 Intent 和广播

java - Android 中 SparseArrayCompat 政策不断增长背后的基本原理是什么?

user-interface - getter在flutter中的null上调用会显示错误屏幕

c++ - 使用 C++ GUI 应用程序检查网络状态的 QT

java - 如何刷新面板?