2

为了获得自定义的溢出菜单,我使用了子菜单作为

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    //Create the search view
    SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());

    mListView = getListView();
    mListView.setTextFilterEnabled(true);

    setupSearchView(searchView);

    menu.add(0, 1, 1, "Export")
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS| MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(0, 2, 2, "Import")
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(0, 3, 3, null)
    .setIcon(R.drawable.ic_action_overflow)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    SubMenu subMenu = menu.addSubMenu(0, 0, 2, null);

    subMenu.add(0, 4, 4, "Search Message")
    .setIcon(R.drawable.ic_search)
    .setActionView(searchView)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);


    subMenu.add(0, 5, 5, "Settings")
    .setIcon(R.drawable.ic_settings);

    subMenu.add(0, 6, 6, "About")
    .setIcon(R.drawable.ic_about);

    MenuItem subMenuItem = subMenu.getItem();
    subMenuItem.setIcon(R.drawable.ic_action_overflow);
    subMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return super.onCreateOptionsMenu(menu);
}

这让我的行动项目为

在此处输入图像描述

我唯一的问题是,在更宽的屏幕上,我还获得了默认溢出菜单以及我自己的自定义溢出菜单。如何隐藏默认溢出菜单?

4

0 回答 0