How to use actionbarsherlock for Google maps menu?

流过昼夜 提交于 2019-12-24 03:15:22

问题


Please view image of Google maps fig 1. from the link below:

http://www.androidpatterns.com/uap_pattern/search-%E2%80%93-main-menu

Currently onCreateOptionsMenu(Menu menu) {} will add menu to action bar. How to create menu below?

Finally:

  1. How do I control both Menu options below and Action bar above.
  2. Is there any source code or demo for the same available.

回答1:


On pre-Honeycomb the overflow menu for ActionBarSherlock (that is, item that do not fit into the action bar) will be placed in the normal options menu by default.

Your posted screenshot can be achieved using the following:

public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Places")
        .setIcon(R.drawable.ic_places)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menu.add("Layers")
        .setIcon(R.drawable.ic_layers)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menu.add("My Location")
        .setIcon(R.drawable.ic_location)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menu.add("Search")
        .setIcon(R.drawable.ic_search)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menu.add("Directions")
        .setIcon(R.drawable.ic_directions)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    menu.add("Starred Places").setIcon(R.drawable.ic_starred);
    menu.add("Clear Map").setIcon(R.drawable.ic_clear);
    menu.add("Join Latitude").setIcon(R.drawable.ic_latitude);
    //Whatever else is under the "More" menu
    return true;
}

Here's a screenshot from one of the sample application that come with the library demonstrating this on Android 2.3.3:

When running on a Honeycomb or a ICS device (with no hardware menu button) the overflow menu becomes the last item on the action bar and shows up in a dropdown list.




回答2:


They are mutually exclusive. As of Android v3.0, the menu at the bottom has been replaced with the ActionBar "overflow" (the icon top-right with three dots).

So on Android 3.0 devices, the menu will open top-right, on older devices, it'll appear at the bottom. The image attached shows the Android 4 way of doing things.

http://developer.android.com/design/patterns/actionbar.html



来源:https://stackoverflow.com/questions/9863403/how-to-use-actionbarsherlock-for-google-maps-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!