蜂窝动作栏和电话应用程序
我已经写了我的第一个应用程序几周了,今天我意识到,如果我们想为 Honeycomb 和普通手机进行开发,我们应该将它们打包为一个应用程序,而不是作为两个具有不同目标的应用程序。
因此,我在 Eclipse 中启动了一个目标为 2.1(SDK 级别 7)的新项目,并将我的 Java、XML 和其他资源从旧的(面向 Honeycomb 的项目)复制到新的(面向手机 + 平板电脑的项目)。
一切都很顺利,直到我遇到了 ActionBar 代码的问题,特别是我将应用程序图标设置为转到主要活动的地方 - 由于某种原因它不喜欢这样。
我们应该如何为两个平台编写一个应用程序?我认为它就像两个版本的布局和 Java 中的一些小调整一样简单。
I have been writing my first app for a few weeks and today I realised that if we want to develop 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
到目前为止,我发现的最好的例子是 Google IO 2011 Schedule,可以在 http:// /code.google.com/p/iosched/。该项目是专门为此目的而构建的 - 1 个 apk 提供了一个适用于手机的应用程序版本和另一个适用于平板电脑的应用程序版本。根据您的应用程序的结构,通过一些调整(主要或次要取决于您的观点),应用程序可以为两个设备平台做几乎任何事情。
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.
ActionBar
首次在 Android 3.0 中引入。如果您希望应用程序在更高版本上运行,则必须检查
ActionBar
是否可用(然后运行特定的代码),如果不是,您将不得不想出另一个解决方案(也许是您自己的实现)。Build.VERSION 可用于确定您的应用的 Android 版本正在运行。
The
ActionBar
was first introduced in Android 3.0If 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.
我仔细研究了新的(面向手机+平板电脑的)项目,看看是否有任何我错过的东西会导致问题。
事实证明,在 androidmanifest.xml 中,我的targetsdk 和 minsdk 级别错误。
我已将它们更改为正确的:
此更改解决了问题。感谢您的帮助。
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:
This change fixed the issue. Thanks for the help.