如何使用整数设置颜色? [英] How to set color using integer?

查看:307
本文介绍了如何使用整数设置颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整数形式的颜色代码(例如13369395)转换为android专用.由于13369395也是我尝试做的整数

How can i convert color code in integer ex: 13369395 to android specific. Since 13369395 is also an integer i tried doing

mainLayout.setTextColor(13369395);

,但不起作用.

我还尝试将13369395转换为十六进制,例如:

I also tried converting 13369395 to hexadecimal like:

mainLayout.setBackgroundColor(Integer.parseInt(13369395 +"", 16)+0xFF000000);

但这也无济于事.

推荐答案

我找到了解决方案.只需使用十六进制就可以了,如下所示:

I got the solution. Just a work around with Hexadecimal as below:

Integer.toHexString(colour);

如果仅由

mainLayout.setBackgroundColor(Integer.parseInt(hexVal,16));

它不会工作.您需要将蒙版添加为

it wont work. You need to add mask as

mainLayout.setBackgroundColor(0xff000000 + Integer.parseInt(hexVal,16));

这已解决了问题

这篇关于如何使用整数设置颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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