androidcolorsbackgroundhex

How to setBackgroundColor as Color, not as int


How to set setBackgroundColor if I have got Color(Long) or how to get hex from Color?

enum class ColorRes(val color: Color, val resource: Int)
SIZE(Color(0xFFFF655C), R.drawable.size_icon)

.setBackgroundColor(colorRes.getColor()).  ??

Solution

  • I can't remember that android.graphics.Color had a constructor with single Int parameter. AFAIK, String and Int representations of hex color are convertible into a Color object. I wonder why you need to hold android platform specific class object, but however, we have a method to convert Color into Int, but it is

    Added in API level 26

    regarding the documentation