If i defined a color in resources
#123456
it\'s possible
All of the solutions here using Integer.toHexString() break if you would have leading zeroes in your hex string. Colors like #0affff would result in #affff. Use this instead:
String.format("#%06x", ContextCompat.getColor(this, R.color.your_color) & 0xffffff)
or with alpha:
String.format("#%08x", ContextCompat.getColor(this, R.color.your_color) & 0xffffffff)