Mark F Mark F - 2 years ago 786
Android Question

Cannot Resolve ContextCompat in Android

I have an AlertDialogue object called dialog. I am attempting to add an icon to it. I see that this syntax is now deprecated:


I'm reading everywhere that this should work:

dialog.setIcon(ContextCompat.getDrawable(context, R.drawable.myImage));

However, the ContextCompat syntax is not being recognized by Android Studio. Is there something that I should be importing? Thank you.

Answer Source

ContextCompat is part of support library v4. Have you added support library 4 to your project?

You can include support library to your build.gradle file under app folder if you haven't already

dependencies {
// other stuff here
    compile ''
// update the 23.0.0 to latest version available

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download