2
votes

I implemented an app that works from 2.1 and on. But my app has the menu functionality to exit from the app. I installed the app in an Ice Cream Sandwich (ICS, version 4.0) device and it's working fine. But ICS doesn't have menu buttons - instead of this it has the action bar. I am new to this concept. I want to integrate this into my app. I tried but I am not succeeding.

For this I follow these steps:

  1. android:targetSdkVersion="11" in the Android manifest.
  2. android:showAsAction="ifRoom|withText" --> add to menu.xml (which is in the menu folder) but I get the following error:

No resource identifier found for attribute 'showAsAction' in package 'android'

2
Try this one. Also this Developer's blogPraveenkumar

2 Answers

2
votes

You should start with a working Options Menu implementation. Test it on a 1.x or 2.x emulator to make sure it works. Then set your targetSdkVersion to >=11 (if it isn't already) and verify the menu appears in the ActionBar on >= 3.0. Only devices or emulators running Android 3.0 or above will draw an Action Bar. Older versions still use the Options menu. Once the menu appears in the ActionBar, you can start adding the showAsAction attribute to individual items in the menu XML.

To set targetSdkVersion:

Open up your Project properties, select Android, and select an Android SDK to link your project against. For both the Project properties and your Android Manifest targetSdkVersion, I recommend using the newest SDK available.

Screen shot illustrating setting targetSdkVersion

minSdkVersion defines the lowest version of Android the app will run on. targetSdkVersion defines the highest version of Android the app knows about when built -- which classes and methods are available, what constants are defined, etc. It may run on newer versions, but it won't know about any features added after targetSdkVersion.

More information about API Level.

If you want an ActionBar to display on Android <3.0, make a project based on Action Bar Sherlock or the Action Bar Compatibility sample from the SDK. But don't try this until you are comfortable with your ActionBar in >= 3.0.

0
votes

you may find a good Example code over here.