How do I use ActionBarActivity in an application that runs with android 2.2 or higher?

0

I want to use Action Bar in my application that will also run on devices running Android 2.2 or higher. I know I should use Class ActionBarAcitivity , which is the API made available by Google. I already downloaded the Android Support Library and Repository and I imported the class android-support-v7-appcompat . In this class android-support-v7-appcompat I added to the build path the .jar and added these .jar to my class that specializes ActionBarActivity .

On the main screen I made it specialize and import the ActionBarActivity , but in manifest I can not change from the android:theme="@style/AppTheme" theme to the ActionBarActivity android:theme = "@style/Theme.AppCompat.Light" themes.

When I try to generate an error:

  

"Error: No resource found that matches the given name (at 'theme' with   value '@ style / Theme.AppCompat.Light').

Remarks: When I add the .jars of android-support-v7-appcompat to my class, the class R some.

How do I use ActionBarActivity in an application running with Android 2.2 or higher?

    
asked by anonymous 12.02.2014 / 22:38

3 answers

2

After you create a new project, the best way I found in eclipse was to do:

  

File -> Import -> existing Android code -> navigate to ".. \ sdk \ extras \ android \ support \ v7" -> select the directory "appCompat" -> Copy to Desktop "-> Finish

After doing this you will have a new project named android-support-v7-appcompat .

Then go to the project you want to use the library and:

  

Right-click - properties -> android-> add and the project you imported above will appear, select it and you can go to the manifest and change the theme to Theme.appCompat.Light .

If you're going to work with the latest versions, I also suggest that you go to the values/styles.xml directory and rewrite the themes to ActionBarCompat and to the latest versions like this:

<style name="MinhaAbCompat" parent="@style/Theme.AppCompat.Light.DarkActionBar">


</style>

<style name="MinhaAbNormal" parent="@android:style/Theme.Holo.Light.DarkActionBar">

</style>

And so you can later customize your themes for both older and older versions.

    
13.02.2014 / 13:56
1

You can use this Theme to set android:targetSdkVersion at least to API Level 11.

However, it is recommended that android:targetSdkVersion always point to the latest API.

android:targetSdkVersion=19  

This, in addition to solving the problem of Theme , will also solve the problem of R and any other errors related to No resource found that matches the given name ....

I also came across this problem. When I found the solution, I asked a question / answer on SO.com

    
13.02.2014 / 00:32
0

Use the ActionBarSherlock: library.
ActionBarSherlock

    
13.02.2014 / 14:30