删除 Android 中的 Paint Flag

发布于 2024-11-26 07:06:32 字数 298 浏览 1 评论 0原文

我的代码如下所示:

    TextView task_text = (TextView) view.findViewById(R.id.task_text);
    task_text.setPaintFlags( task_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

这会导致文本上出现删除线效果。但是,我想知道如何删除设置后的标志,以及如何检测设置了标志。

我知道这是一个按位运算,但我尝试过 ~ 和 - 运算符,但都不起作用。

My code looks like this:

    TextView task_text = (TextView) view.findViewById(R.id.task_text);
    task_text.setPaintFlags( task_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

This causes a strike through effect to appear on the text. However, I'd like to know how to remove the flag once set, and how to detect that the flag is set.

I understand this is a bitwise operation, but I've tried both ~ and - operators, neither work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

北座城市 2024-12-03 07:06:32

要删除标志,这应该可行:

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

这意味着设置除 Paint.STRIKE_THRU_TEXT_FLAG 之外的所有设置标志。

检查是否设置了标志(编辑:有一段时间我忘记了它是java......):

if ((task_text.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) > 0)

To remove a flag, this should work:

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

Which means set all the set flags, except of Paint.STRIKE_THRU_TEXT_FLAG.

To check if a flag is set (Edit: for a moment I forgot it is java...):

if ((task_text.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) > 0)
樱花落人离去 2024-12-03 07:06:32

在科特林中

task_text.paintFlags = task_text.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()

In Kotlin

task_text.paintFlags = task_text.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
不乱于心 2024-12-03 07:06:32

这也有效:

task_text.setPaintFlags(0);

This also works:

task_text.setPaintFlags(0);
夜还是长夜 2024-12-03 07:06:32

使用异或运算符^代替|&(~)组合:

// setup STRIKE_THRU_TEXT_FLAG flag if current flags not contains it
task_text.setPaintFlags(task_text.getPaintFlags() ^ Paint.STRIKE_THRU_TEXT_FLAG));

// second call will remove STRIKE_THRU_TEXT_FLAG
task_text.setPaintFlags(task_text.getPaintFlags() ^ Paint.STRIKE_THRU_TEXT_FLAG));

检查当前是否设置了标志:

if((task_text.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) == Paint.STRIKE_THRU_TEXT_FLAG)

Use exclusive OR operator ^ instead of | with &(~) combination:

// setup STRIKE_THRU_TEXT_FLAG flag if current flags not contains it
task_text.setPaintFlags(task_text.getPaintFlags() ^ Paint.STRIKE_THRU_TEXT_FLAG));

// second call will remove STRIKE_THRU_TEXT_FLAG
task_text.setPaintFlags(task_text.getPaintFlags() ^ Paint.STRIKE_THRU_TEXT_FLAG));

Check if flag is currently setup:

if((task_text.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) == Paint.STRIKE_THRU_TEXT_FLAG)
你不是我要的菜∠ 2024-12-03 07:06:32

在我看来,
只需设置其默认标志是更好的选择。否则,文本会显得锯齿状。 TextView(EditText扩展TextView)中的默认标志是

Paint.ANTI_ALIAS_FLAG

并设置一个新的paintflag将替换以前的。我做了一个测试来验证一下。所以,就像这样:

task_text.setPaintFlags(Paint.ANTI_ALIAS_FLAG);

In my opinion,
just set its default flag is a better choice. Otherwise, the text will be looked jagged. The default flag in TextView (EditText extends TextView) is

Paint.ANTI_ALIAS_FLAG

And set a new paintflag will replace the previous one. I have made a test to verify it. So, just like this:

task_text.setPaintFlags(Paint.ANTI_ALIAS_FLAG);
反差帅 2024-12-03 07:06:32

|------------------------------------------------ -|
|<*>|使用 textView 下划线:
|------------------------------------------------ -|

|*|添加下划线:

 txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

|*|删除下划线:

txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() ^ Paint.UNDERLINE_TEXT_FLAG);

|*|检查下划线:

if((txtVyuVar.getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) == Paint.UNDERLINE_TEXT_FLAG)
{
    // Codo Todo
}

|*|切换下划线:

if((txtVyuVar.getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) == Paint.UNDERLINE_TEXT_FLAG)
{
    txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() ^ Paint.UNDERLINE_TEXT_FLAG);
}
else
{
    txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}

|--------------------------------------------------|
|<*>| Underline with a textView :
|--------------------------------------------------|

|*| Add Underline :

 txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

|*| Remove Underline :

txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() ^ Paint.UNDERLINE_TEXT_FLAG);

|*| Check Underline :

if((txtVyuVar.getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) == Paint.UNDERLINE_TEXT_FLAG)
{
    // Codo Todo
}

|*| Toggle Underline :

if((txtVyuVar.getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) == Paint.UNDERLINE_TEXT_FLAG)
{
    txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() ^ Paint.UNDERLINE_TEXT_FLAG);
}
else
{
    txtVyuVar.setPaintFlags(txtVyuVar.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
青衫儰鉨ミ守葔 2024-12-03 07:06:32

Text查看详情_实际_价格;
//并从您的xml文件中查找iddetails_actual_price.setPaintFlags

(details_actual_price.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

TextView details_actual_price;
//and find id from your xml file

details_actual_price.setPaintFlags(details_actual_price.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

想你只要分分秒秒 2024-12-03 07:06:32

//用于适配器调用

Textviewdetails_actual_price;
//并找到id
holder.actulPrice.setPaintFlags(holder.actulPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

//used for adapter calss

Textview details_actual_price;
// and find id
holder.actulPrice.setPaintFlags(holder.actulPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

眼藏柔 2024-12-03 07:06:32

我尝试在 kotlin 中使用 kotlin 按位运算符使用上述方法,但得到了奇怪的结果......

所以为了删除我刚刚所做的标志

view.paintflags = 0x00

I tried using the above mentioned methods in kotlin using kotlin bitwise operators and I was getting weird results...

so to remove a flag I just did

view.paintflags = 0x00
追风人 2024-12-03 07:06:32

在 Kotlin 中:

设置“删除线”标志:

numberTextView?.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG

删除此标志:

numberTextView?.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG and Paint.STRIKE_THRU_TEXT_FLAG.inv()

In Kotlin:

to set "strike thru" flag:

numberTextView?.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG

to remove this flag:

numberTextView?.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG and Paint.STRIKE_THRU_TEXT_FLAG.inv()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文