Android menu and action bar conversion

前端 未结 4 792
感动是毒
感动是毒 2021-02-09 20:41

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 applicati

相关标签:
4条回答
  • 2021-02-09 20:58

    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.

    0 讨论(0)
  • 2021-02-09 21:16

    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.

    0 讨论(0)
  • 2021-02-09 21:22

    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.

    0 讨论(0)
  • 2021-02-09 21:24

    You can use Build.VERSION to do something different in every versions。 Some like Build.VERSION.SDK_INT<Build.VERSION_CODES.HONEYCOMB

    0 讨论(0)
提交回复
热议问题