How do I use Actionbaractivity in an application that runs on android 2.2 or higher?

Asked

Viewed 2,797 times

0

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

On the main screen I made her specialize and import the ActionBarActivity, but in the manifest I can’t change the subject android:theme="@style/AppTheme" for the themes of ActionBarActivity android:theme = "@style/Theme.AppCompat.Light".

When I try an error is generated:

"Error: No Resource found that Matches the Given name (at 'Theme' with value '@style/Theme.AppCompat.Light').

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

How to use the ActionBarActivity in application that runs with Android 2.2 or higher?

  • Take a look at this video lesson. http://www.thiengo.com.br/criando-supporte-actionbar-android-com-actionbarsherlock

3 answers

2


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

File->import->existing Android code->navigate to ".. sdk extras android support v7"->select the directory "appCompat"->Check the option "Copy to desktop"->finish

After doing this you will have a new project with the name android-support-v7-appcompat.

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

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

If you will work with the latest versions also I suggest you go to the directory values/styles.xml and rewrote the themes for ActionBarCompat and for the latest versions so:

<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.

  • Ta right Paulo. no problem I speak the PT so so the writing. Thanks for the chore.

  • I do not know exactly what I was doing wrong, yesterday I hit my head too much with it, but this morning I did all the steps again, gathering the tips of Ramaral and yours and everything worked out! Obrigado Paulo!

1

You can use this Theme has to define the android:targetSdkVersion minimum for Level 11 API.

However it is advisable 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 R problem 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 AS.

  • Doing the tests here ramaral, for now I did not get results. Maybe I missed some step of the configuration. Thanks in advance for the help!

  • Ramaral his tips were of great value, I joined the same with the tips of Paulo and everything went well. I don’t know exactly what I was doing wrong or failing to do, but this morning I retraced all the steps and succeeded. Thank you again Ramaral =)

0

  • Thanks Carlos, but I got it from Appcompat anyway!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.