我有一个函数,它接收一个字符串作为名为“color”的参数。颜色类似于“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");
关于java - 如何从 String 传递 setColor 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50746141/