java - 如何从字符串传递 setColor 参数
问题描述
我有一个函数,它接收一个字符串作为名为“颜色”的参数。颜色类似于“FFF267”。现在我想做drawable.setColor(0xF0FFF267)。我该怎么做?我尝试了以下方法,但它引发了异常。
ImageView circ = (ImageView) findViewById(R.id.circle);
GradientDrawable drawable = (GradientDrawable) circ.getDrawable();
drawable.setColor(0xF0 + Integer.toHexString(Integer.parseInt(color)));
解决方案
用这个
Color.parseColor("yourcolorstring");
推荐阅读
- delphi - Delphi - 如何更改 t 图表系列的调色板?
- android - 尝试写入 .json 时应用程序崩溃
- android - AdMob 广告不显示在 Unity 中
- api - 如何将 spark 数据框中的列(列表)合并到组中?
- reactjs - 为什么 React 说“注销不是一个函数?”
- r - 转换data.table的多个日期列
- ipad - SwiftUI 换行自适应网格
- html - 无法使用 CSS 网格/网格模板区域布局页面
- elasticsearch - 如何从elasticsearch中的结果集中搜索结果集
- python - 在 Python 中填充列表的一部分/等效于 std::fill