Egor
Egor

Reputation: 317

New Android Studio: Cannot resolve symbol 'ContextCompat'

After updating Android Studio, I found some red rows in my project.

What I have.

I call this method:

if (Build.VERSION.SDK_INT < 21) {
    orangeProgressBar(progressBar);
}

Using of red ContextCompat.getColor(): enter image description here

private void orangeProgressBar(ProgressBar pb) {
    int color = ContextCompat.getColor(pb.getContext(), R.color.orange);
    ...
}

Of course, importing:

implementation 'com.android.support:support-v4:24.2.1'

import android.support.v4.content.ContextCompat; enter image description here

Studio can't import content.ContextCompat, because it seems like android.support.v4.content. have not this child

Upvotes: 1

Views: 4930

Answers (2)

SammyT
SammyT

Reputation: 769

Deleting the .gradle and .idea did not work for me. What worked was the following:

In Android Studio close all projects

In the Welcome To Android Studio Screen:

  • remove all the projects by clicking the X in the top right corner, or right click, choose "Remove Selected From Welcome Screen"
  • Close Android Studio
  • Re-open Android Studio,
  • Open an existing Android Studio project Navigate to the project
  • It re-built and the errors were gone.

Upvotes: 3

Manish Karena
Manish Karena

Reputation: 734

I had the same problem after updating the Android Studio but the below solution worked for me:

Deleting the .gradle and .build folder from your respective project directory structure and rebuild the project.I'm not so sure about what it does but i think it deleted all the previous build caches other build related files and regenerated it that's why it's worked for me.

Upvotes: 2

Related Questions