Pregunta

I have int CYAN in Color class and get requested color from database

valueColor = this.getArguments().getString("valueColor", valueColor);

that is String "CYAN". How do I use this string as integer variable name in the following example?

int[] color = {color.CYAN,Color.WHITE};
¿Fue útil?

Solución

You can parse the color string, thus:

colourString = getArguments().getString("valueColor", colourString);
int valueColor = Color.parseColor(colourString);

You may need to .toLower() as the docs only lists lower case examples: http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top