Honeycomb ActionBar & Phone App
I have been writing my first app for a few weeks and today I realised that if we want to d开发者_运维技巧evelop for Honeycomb and normal phones, we are supposed to package them together as one app rather than as two apps with different targets.
So I started a new project in Eclipse with a target of 2.1 (SDK level 7) and copied over my Java, XML and other resources from the old (Honeycomb oriented project) to the new (phone + tablet oriented) project.
All was going well until I hit a snag with the ActionBar code, in particular where I set the app icon to go to the main activity - it does not like this for some reason.
How are we supposed to write one app for both platforms? I thought it would be as simple as two versions of the layout and a few MINOR tweaks in Java.
The best example I've found so far is the Google IO 2011 Schedule, which is freely available at http://code.google.com/p/iosched/. The project was built specifically for this purpose - 1 apk provides a version of the app suitable for the phone and another for the tablets. Depending on how your app is structured, with some tweaking (major or minor depending on your perspective) the app can do pretty much anything for the two device platforms.
The ActionBar
was first introduced in Android 3.0
If you want your app to run with further versions, you'll have to check if the ActionBar
is available (and then run the particular code) and if it's not, you'll have to come up with another solution (maybe your own implementation).
Build.VERSION can be used to determine what Android version your app is running on.
I looked closer at the new (phone + tablet oriented) project to see if there was anything I had missed that would be causing the problem.
It turns out in the androidmanifest.xml I had the wrong targetsdk and minsdk levels.
I have changed them to the correct ones:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="11" />
This change fixed the issue. Thanks for the help.
精彩评论