If you just want to use some of the predefined Android colors, you can use Color.COLOR (where COLOR is BLACK , WHITE , RED , etc.):
myView.setBackgroundColor(Color.GREEN);
Otherwise, you can do as others have suggested,
myView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.myCustomGreen));
I do not recommend using hexagonal color directly. You must save all your custom colors in colors.xml.
Suragch Jan 06 '17 at 5:28 2017-01-06 05:28
source share