开发者

Menu key doesn't appear for my app on honeycomb?

I've got a project which links to API level 11. When I run this on phones, and hit the menu key, my menu shows up fine. When I run on a device which is running android 3.0.1, the menu key does not appear for the same activity:

Any idea why the menu key wouldn't show for this activity?

@开发者_Python百科Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(...);
    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    menu.add(...);
    return super.onPrepareOptionsMenu(menu);
}

Shouldn't the menu key be appearing for this activity?

Thanks

----- Update --------------------

After some more searching, found this thread on the same issue: http://groups.google.com/group/android-developers/browse_thread/thread/c4b1b835060bd93f

Hackborn says the menu button will be shown if you do not target sdk 11. Which I was doing. So I have a very odd setup now:

<manifest>
  <uses-sdk 
    android:minSdkVersion="5" 
    android:targetSdkVersion="10" />

  <application 
    android:hardwareAccelerated="true" >
  </application>
</manifest>

and in my project properties, I am linked to sdk 11. The reason I'm linking to sdk 11 is so that I can use the "hardwareAccelerated=true" flag in the manifest as above.

So to summarize, I'm linked to sdk 11 in project settings, but setting targetSdkVersion=10 in the manifest. Is that legit? I thought they would have to match,

Thanks


It's legit in that it will work, it's not legit in terms of Android user experience standards. :)

The reason you don't get a menu button in the system bar when you target API 11 is that we only show it for supporting legacy apps. New apps should use the action bar to present options for your activity. The action bar will be populated by the same mechanisms that populate your options menu on previous versions.

Target API 11 and make sure you're not disabling the title bar in your theme or in your activity and you will get an action bar by default. The menu will appear in the upper right.


That's legit: it'll build fine, and will work fine as well. I'm not aware of any problems that would ensue: the docs explicitly say you can target a lower version than you are building against.


Simply remove android:targetVersion attribute in manifest file and use android:minSdkVersion="8" minsdk version should be lower than your device version

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜