Alright, so i have an Activity. In the activity there is a textview and a button. The button launches a ColorPicker and when the color is chosen, it will place the hex value in the textview.
Now, in a service i am attempting to convert the string to a color int. Then set an imageview background color the hex value from the textview. See example below…
In my main.xml i have a textview and a button. The Textview will have the hex value set in its text.
In my service, i have an imageview. To set the background color of the imageview, i got the text from the textview in the main activity then made a string. Then i converted it to a Int. But when i dry to set the color as a background it will Force close!
`BatteryBarTop = (ImageView) view.findViewById(R.id.battery_bar_top);
String tbColor = Setting.ColorValue.getText().toString();
int color = Color.parseColor(tbColor);
BatteryBarTop.setBackgroundResource(color);`
If i put a hex value in for “color” it will work perfectly. But i need the hex value from the textview be the color as it can be changed when needed…
You are calling
setBackgroundResource(). This expects a resource ID. UsesetBackgroundColor()to set a color.