简体   繁体   English

Android Linkify 如何设置自定义链接颜色?

[英]Android Linkify how to set custom link color?

I want to set my android linkify text color to a custom color however mText.setLinkTextColor("#2f6699");我想将我的 android 链接文本颜色设置为自定义颜色,但是mText.setLinkTextColor("#2f6699"); does not work, I have been searching for a built in method that will compile a hexidecimal value but I havent found one, any help will go a long way thanks不起作用,我一直在寻找一种可以编译十六进制值的内置方法,但我还没有找到,任何帮助都会大有帮助,谢谢

You should convert it to a Color.您应该将其转换为颜色。 Try:尝试:

mText.setLinkTextColor(Color.parseColor("#2f6699"));

您也可以在 xml 中使用android:textColorLink="#2f6699"

Try something like this:尝试这样的事情:

noteView.setLinkTextColor(Color.green);

If you want to set an hexadecimal color:如果要设置十六进制颜色:

noteView.setLinkTextColor(Color.argb(int alpha, int red, int green, int blue));

Replacing alpha/red/green/blue with the desired values.用所需的值替换 alpha/red/green/blue。 The documentation on the Color class can be found here可以在此处找到有关 Color 类的文档

As resources.getColor() function deprecated we can try this alternative way.由于 resources.getColor() 函数已弃用,我们可以尝试这种替代方法。

textView.setLinkTextColor(ContextCompat.getColor(this,R.color.colorBlue)) textView.setLinkTextColor(ContextCompat.getColor(this,R.color.colorBlue))

Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM