【发布时间】:2015-08-27 06:54:18
【问题描述】:
我有一种方法可以为我提供一个数组,其中包含我需要绘制到画布渐变中的颜色的 ARGB 部分。但据我所知,这个渐变只接受代表颜色的十六进制数。所以我根据我在这里找到的信息做了一个函数。
这是函数:
public static long getIntegerHexFromARGB(int a, int r, int g, int b){
String hex = String.format("#%02x%02x%02x%02x", a, r, g, b);
return Long.parseLong(hex,16);
}
这就是我所说的:
long rgba_outter_circle = FormulaHelpers.getIntegerHexFromARGB(argbCircleColor[0], argbCircleColor[1], argbCircleColor[2], argbCircleColor[3]);
我的问题是这段代码在我正在做的自定义视图中,以便将其包含在布局中,而 Android Studio 布局编辑器对此声称:
java.lang.NumberFormatException: For input string: "#64FF0000"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:430)
at java.lang.Long.valueOf(Long.java:513)
at math.FormulaHelpers.getIntegerHexFromARGB(FormulaHelpers.java:41)
at framework.joystickController.JoystickButtonView.onMeasure(JoystickButtonView.java:177)
at android.view.View.measure(View.java:17430)
... and much more
它声称的行是 FormulaHelpers:41,即:
return Long.parseLong(hex,16);
有人能看出我做错了吗?我在任何地方都找不到问题 对不起我的英语
【问题讨论】:
-
颜色是一个int,而不是一个long。
-
Color.argb(a, r, g, b)返回一个 int (顺便说一句正确的颜色)。您如何使用rgba_outter_circle? -
从您的公式中删除“#”
-
使用:
return Integer.parseInt(hex.replaceFirst("#", ""), 16); -
感谢您的帮助!
标签: java android colors integer hex