I'm trying to parse an ARGB hex String
to an int
but it's not working.
My code:
int color = Integer.parseInt("ff686868", 16);
Exception:
java.lang.NumberFormatException: unable to parse 'ff686868' as integer
at java.lang.Integer.parse(Integer.java:438)
at java.lang.Integer.parseInt(Integer.java:422)
...
When I try to parse a normal RGB String
like 686868
it does work but when I add the alpha it breaks down. I hope someone can help me.
The number would be too big for integer.
Use: Long.parseLong(..)
使用java.lang.Long.parseLong()
- int
是带符号的,因此它只有31位+ 1个符号位,并且全部使用4 * 8 = 32位。
您可以使用Color.parseColor(String)
来获取int
Color.parseColor(String);
如果itz hexacode这样做
Color.parseColor("#ffffff");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.