来自TextView的getCurrentTextColor返回怪异的颜色 [英] getCurrentTextColor from a TextView returns a weird color

查看:85
本文介绍了来自TextView的getCurrentTextColor返回怪异的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从textView中获取文本颜色并进行比较,以执行某些操作或其他任何操作.

I'm trying to get the text color from a textView and compare it, to do some action or any other.

if (tvTitle.getCurrentTextColor() == -48060){
    isAccepted = 1;
} 

如您所见,目前我必须将其与"-48060"进行比较,因为这是 getCurrentTextColor()返回的内容.

As you can see, at the moment I've to compare it as "-48060" because this is what getCurrentTextColor() is returning.

原始颜色为#ff4444

The original color is #ff4444

我必须以某种方式解析此-48060以获得ff4444吗?

Do I've to parse this -48060 in any way to get ff4444?

谢谢.

推荐答案

只需将其视为unsigned int.

Just treat it as unsigned int.

我对实际颜色为 0xffff4444 表示肯定-多余的两个"f"用于alpha.设置最高有效位,这意味着,如果将该值解释为int,则它将为负值.如果将其强制转换为无符号整数,则将获得相当大的正数.

I'm 99% positive that the actual color is 0xffff4444 - the two extra "f's" are for alpha. The most significant bit is set, which means, that if the value is interpreted as an int, it will be a negative value. If you cast it to an unsigned int, you will get a rather large positive number.

如果您要做的就是像在代码中那样比较值,则还可以在其中放置一个十六进制值,例如:

If all you want to do is compare the value like you do in your code, you can also put a hex value there, for example :

if (tvTitle.getCurrentTextColor() == 0xff4444){
    isAccepted = 1;
} 

这篇关于来自TextView的getCurrentTextColor返回怪异的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆