The error code

ContextCompat.getColor(applicationContext, R.color.primary)
Copy the code

The correct code

ContextCompat.getColor(context, R.color.primary)
Copy the code

You must use the Activity Context, not the Application Context for convenience