Unresolved reference: ContextCompat in Kotlin Android
private fun getDefaultCustomTabsIntentBuilder(activity: Activity): CustomTabsIntent.Builder { val backArrow = getBitmapFromVectorDrawable(activity) return CustomTabsIntent.Builder() .addDefaultShareMenuItem() .setToolbarColor(activity.resources.ContextCompat.getColor(R.color.colorPrimary)) .setShowTitle(true) .setCloseButtonIcon(backArrow!!)
When I am using ContextCompat it shows Unresolved reference: ContextCompat . I am new with this Tnx in Advance
Do it like this:
private fun getDefaultCustomTabsIntentBuilder(activity: Activity): CustomTabsIntent.Builder { val backArrow = getBitmapFromVectorDrawable(activity) return CustomTabsIntent.Builder() .addDefaultShareMenuItem() .setToolbarColor(ContextCompat.getColor(activity,R.color.colorPrimary)) .setShowTitle(true) .setCloseButtonIcon(backArrow!!) }
My ContextCompat
is the member of androidx.
So I import androidx.core.content.ContextCompat
on the top of file.
And then I can use ContextCompat like this ContextCompat.getColor(context, R.color.dark)
.