I have an Android application that targets API 17 and has a minimum SDK version of 8. I'm not interested in providing the ActionBar in devices with Android API < 11, but I'd like to use in the devices running Android >= 3.0.
Browsing stackoverflow in order to learn how to do so, I stumbled upon this question: How to code backward compatible new feature in Android SDK?. I wanted to use the implementation provided in its answer, but I can't import android.app.ActionBar. Eclipse would not recognise it.
What could be the problem? Thanks in advance.
Make sure that your project is referencing the android.jar file for the target, rather than the minimum SDK.
In eclipse, right click project -> Build Path -> Configure Build Path, and see which Android version is referenced there.
Why not use action bar sherlock ?
As mentioned here
Beginning with Android 3.0 (API level 11), the action bar appears at
the top of an activity's window when the activity uses the system's
Holo theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling
requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom
theme with the windowActionBar property.
Related
I have made a programm based on SDK 7. Now I want to add an Actionbar to it. I changed the minSDK to 11 in the Manifest. Isn't that supposed to change the design of the layouts I already have?
Problem is, that I get returned "null" by getActionbar(). I read, that I have to activate the title bar in the OnCreate of the mainactivity. But that does'nt change anything, still "null".
I can see the titlebar, but on SDK 7 it's smaller than on SDK 11. Can't really describe my problem. I just want to use Actionbar on my old written App. But the Layout still looks like in the pic below (left).!
LayoutProblems
Hope someone can help me.
Thanks!
You should also replace the old android.jar with the new one from SDK 11 to get the new GUI. If you are using eclipse for development, just check different Project buid target under Project - Properties - Android.
If you want to use ActionBar in older devices you must use actionbar support library which is provided with the sdk.
I am new to android ,
I am currently working on the FB style slide out menu. I find out many sample project here but could not be able to run that successfully in android 2.2(froyo) version as they are working fine in android 3.x version like HONEYCOMB .
the error occur at ::if(item.getItemId() == android.R.id.home)
here, home is not recognized
and also at::
getActionBar() marking that this method is not defined:
and in values file under res "values-v11" is giving error
thanks in advance for GOOD replies
Most likely, you're using APIs that were only added in Honeycomb, and hence cannot be use in older versions of Android.
These APIs are likely to be the ActionBar and maybe Fragments.
To use these features in older versions, you can use the ActionBarSherlock by Jake Wharton and the Support Library from Google. These collectively allow you to use ActionBars, Fragments etc on older versions of Android.
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:
android:targetSdkVersion="11" in the Android manifest.
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'
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.
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.
you may find a good Example code over here.
There is a new concept in Android:
http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html
But it isn't clear fro me. I have an application which is support from 1.6 to 4.0. And I want to follow the new concept, but I can't set showAsAction property in the menu xml because:
"No resource identifier found for attribute 'showAsAction' in package 'android'"
It's normal because there is in the doc:
"Note: The android:showAsAction attribute is available only on Android 3.0 (API Level 11) and greater."
How can I set the menu, that under 3.0 is a simple menu but over 3.0 as an ActionBar?
Per the blog post that you shared:
Summary
Android no longer requires a dedicated Menu button, some devices don’t have one, and you should migrate away from using it.
Set targetSdkVersion to 14, then test your app on Android 4.0.
Add showAsAction="ifRoom" to menu items you’d like to surface in the action bar.
If the ActionBar doesn’t work for your app, you can remove it with Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.
So, all you really have to do is this:
First, set your SDK min and target version in the AndroidManifest.xml file like this:
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="14" />
Second, add showAsAction="ifRoom" to the menu items in your menu.xml file.
Now run your app in Honeycomb or Ice Cream Sandwich and you should see your menu in the action bar. Your app should still work for the pre Android 3.0 releases.
Go to project properties in Eclipse (right-click on project and select Properties),
then go to Android section, and change Project Build Target to Android 4.0. This must be done so that the build system recognizes showAsAction.
Don't worry that your project won't be runnable on Android less than 4.0, you can still run it as long as you don't call a class or method available only on 4.0.
You can use Build.VERSION to do something different in every versions。
Some like Build.VERSION.SDK_INT<Build.VERSION_CODES.HONEYCOMB
You can use some os technology to provide actionbar in apps with API level less then 11.
Consider using ActionBarSherlock. You can just add it as library project to your project and if you won't set the Sherlock theme it won't show action bar(in case you don't want to show it), yet you can mark your menuitems with "showAsAction". On devices with API level higher than 10, action bar with your menuitems will be normally shown.
I am trying to use the BluetoothChat sample code as a base for an application I am working on. I don't understand why my android.app.ActionBar import isn't working. Eclipse doesn't seem to recognize it. My project build target is the Google API 2.3.1.
Can someone explain to me what I am doing wrong? I don't know how specific I should be so if more info would help you answer my question, please ask me.
android.app.ActionBar works only on 3.0 level 11 API
As mentioned in the android blog available here
Beginning with Android 3.0 (API level 11), the action bar appears at
the top of an activity's window when the activity uses the system's
Holo theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling
requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom
theme with the windowActionBar property.