int backgroundColor = ContextCompat.getColor(context, R.color.my_view_color); // Color backgroundColor = ... (Don't do this. The color is just an int.) myView.setBackgroundColor(backgroundColor);