IDE “Cannot Resolve @style/Theme.Appcompat” when u

2019-01-22 05:30发布

This is not really a huge issue, as my project still builds and runs correctly (using gradle), but I'm having trouble getting Android Studio to recognize the application compatibility theme released in the API 18 SDK (for allowing actionbar support for android 2.1 and above).

I have the support libraries loading successfully, because code completion is possible for the ActionBar classes in java files. The issue is that Android studio shows red text errors for assignments to the Theme.AppCompat.Light in the AndroidManifest.xml.

Is there a way to enable code completion for theme resources declared in the manifest from external libraries in Android Studio?

Updated Here is my <activity> block from my AndroidManifest:

<activity
    android:name="com.example.activities.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.AppCompat.Light" >

I've also tried setting the theme in the application block:

<application
    android:allowBackup="true"
    android:icon="@drawable/main_final_ic"
    android:label="@string/app_name"
    android:logo="@drawable/main_final_enzo"
    android:theme="@style/Theme.AppCompat.Light" >

Again, these both work and compile OK, but appear as red text with errors in my IDE. I've also just confirmed that the same issues are occurring when running my project in eclipse.

12条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-22 06:03

Problem was that my appcompact library projest has been located in different location. On importing I have to check "Copy project into workspace" thats all!

JUST go to Files click on close and then click on existing project and select your android project.... Theme issue will be resolved.

查看更多
淡お忘
3楼-- · 2019-01-22 06:04

Problem was that my appcompact library projest has been located in different location. On importing I have to check "Copy project into workspace" thats all!

查看更多
相关推荐>>
4楼-- · 2019-01-22 06:04

Downgrading build:gradle version 2.3.3 to 2.2.3 worked after struggling for hours!

classpath 'com.android.tools.build:gradle:2.2.3'

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
查看更多
虎瘦雄心在
5楼-- · 2019-01-22 06:06

I had this same issue. Sounds like you have the V7 jar file compiling fine but you are probably missing the xml resource needed.You need to manually include the 'Theme.xml' provided with the V7 package. Here is what I did to fix it.

Look under:Adding libraries with resources http://developer.android.com/tools/support-library/setup.html

The directions provided here aren't very clear because it doesn't tell you to bring any resources in. (maybe a bug in Android Studio?)

Here is what I did:

  1. Update your SDK in the manager and be sure to include 'Android support repository' in extra's
  2. Go to SDK in file explorer (Finder on mac) track down the extra's folder (..\sdk\extras\android\support\v7\appcompat\res\values on Windows). Somewhere in there is a "themes.xml" and "themes_base.xml'. Copy both of these files.
  3. In your project paste the files into 'values' directory
  4. do a rebuilt and that did the trick for me.
查看更多
唯我独甜
7楼-- · 2019-01-22 06:14

Fix was simple for me on android studio.

Click help ---> Check for updates

Then actually read what the prompt says and decide whether you want a bleeding edge update or a stable update.

Once android studio restarts it should be working.

Side Note: Everything was still red underlined for me until I rebuilt the project.

查看更多
登录 后发表回答