Menus - Android Developers Guide

Fundamental type

有一些 menu 行為的轉變

  1. Options menu -> app bar

    • Android 3.0 之後,建議轉用 app bar



  2. Floating context menu -> contextual action mode

    • Long-click: 長按元件後的 UI 變化
    • Android 3.0 之後,建議轉用: contextual action mode

  1. Popup menu
    • 不包含第二項所述, 因長按行為而產生的 floating context menu
    • the popup menu is for extended actions that relate to regions of content in your activity.

Implementation

1. Creating an Options Menu

@Override public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.game_menu, menu);
    return true;
}

2. Handling click events

@Override public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection

    switch (item.getItemId()) {
        case R.id.new_game:
            newGame();
            return true;
        case R.id.help:
            showHelp();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

Comments

comments powered by Disqus
Copyright © 2013 Andro Chen
Powered by Logdown and Greyshade
Favicon from The Noun Project