Can't Find Theme.AppCompat.Light for New Andro

2018-12-31 10:23发布

I am trying to implement the new ActionBar support library that was released by Google a couple days ago. In the past, I have successfully implemented ActionBarSherlock without any issues using the same method listed on Google Developer's Support Library Setup page - using the guide on how to include the resources (which is similar to how ActionBarSherlock did it). I have the library project loaded in to my own project as a library as well.

I can tell the library is loading fine. When, instead of extending Activity on my MainActivity.java, I changed it to extend ActionBarActivity (as per Google's instructions), no errors occur - and it imports correctly.

I even tried bypassing the style.xml file and adding @style/Theme.AppCompat.Light directly in to the AndroidManifest.xml for both <application> and <activity> with android:theme="@style/ThemeAppCompat.Light" with all attempts resulting in the same error.

Now the issue is I cannot get it to change the theme, let alone even build without throwing an error. Below is the error I am receiving, followed by the style.xml file I changed to use the new theme.

I have moderate experience working with Android apps and am running Eclipse with the latest version of the Support Libraries and SDK compiling with API 18 (Android 4.3).

Error Received During Build

error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'. styles.xml /ActBarTest/res/values line 3 Android AAPT Problem

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ProsoftStudio.ACTest" parent="@style/Theme.AppCompat.Light">
    </style>
</resources>

Any suggestions? This was never an issue with ActionBarSherlock. I want to work on using this new support library. It almost seems like the .jar is loading, but not the resources.

30条回答
只靠听说
2楼-- · 2018-12-31 11:04

Quickest solution :

right click on the project - > Android tools -> Add support library..

enter image description here

查看更多
柔情千种
3楼-- · 2018-12-31 11:04

I dont know how many of you noticed this. Support library "appcompat_v7" and your project should be in a same directory(I mean workspace directory). Dont clean your project until its error free else you will have tough time with R.java

查看更多
弹指情弦暗扣
4楼-- · 2018-12-31 11:05

For Android Studio or IntelliJ, all you need to do is update your dependencies in gradle.build. I used the following:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
}
查看更多
浮光初槿花落
5楼-- · 2018-12-31 11:07

You need to do next:

  1. File->Import (android-sdk\extras\android\support\v7). Choose "AppCompat"
  2. Project-> properties->Android. In the section library "Add" and choose "AppCompat"
  3. That is all!

Note: if you are using "android:showAsAction" in menu item, you need to change prefix android as in the example http://developer.android.com/guide/topics/ui/actionbar.html

查看更多
几人难应
6楼-- · 2018-12-31 11:07

works:

<style name="MyApp" parent="Theme.AppCompat.Light">
</style>
<style name="MyApp" parent="@style/Theme.AppCompat.Light">
</style>
<style name="Theme.AppCompat.Light.MyApp">
</style>
查看更多
牵手、夕阳
7楼-- · 2018-12-31 11:09

For Android Studio 1.2.2

Drop "android" from the parent attribute value:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
查看更多
登录 后发表回答