【发布时间】:2013-10-24 19:38:55
【问题描述】:
我正在尝试将十六进制值转换为 int,以便创建新的可绘制颜色。我不确定这是否可能,但根据documentation,它应该。它明确要求
公共 ColorDrawable(整数颜色)
在 API 级别 1 中添加 使用指定的创建新的 ColorDrawable 颜色。
参数 color要绘制的颜色。
所以,我的代码无法正常工作,因为我收到 Invalid int: "FF6666" 错误。有什么想法吗?
int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);
【问题讨论】:
-
如果提供的答案之一解决了您的问题,请考虑将其验证为已接受的答案,以便其他人知道您的问题已解决。
-
有一个很好的实用程序类 android.graphics.Color 有一个方法 parseColor。尝试改用它,不要忘记将尖锐 (#) 前缀附加到您的颜色字符串表示中,例如#FF6666
标签: java android android-drawable colordrawable