@Override
  public boolean onCreateOptionsMenu(Menu menu) {
    optionsMenu = menu;

    // 收藏按钮
    MenuItem favoriteItem = menu.add(0, FAVORITE_ITEM_ID, 100, R.string.footbar_favorite);
    favoriteItem.setIcon(R.drawable.ic_menu_favorite_n);
    MenuItemCompat.setShowAsAction(favoriteItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);

    // 分享按钮
    MenuItem shareItem = menu.add(0, SHARE_ITEM_ID, 101, R.string.footbar_share);
    MenuItemCompat.setActionProvider(shareItem, mShareActionProvider);
    MenuItemCompat.setShowAsAction(shareItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    return true;
  }
Beispiel #2
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.script_menu, menu);
    MenuItemCompat.setShowAsAction(
        menu.findItem(R.id.script_add), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    MenuItemCompat.setActionProvider(
        menu.findItem(R.id.script_add), new AddActionProvider(this)); // 自定义子菜单

    MenuItemCompat.setShowAsAction(
        menu.findItem(R.id.script_view), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    MenuItemCompat.setShowAsAction(
        menu.findItem(R.id.script_setting), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    MenuItem item = menu.findItem(R.id.script_search);
    SearchView searchView = new SearchView(this.getSupportActionBar().getThemedContext());
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    MenuItemCompat.setActionView(item, searchView); // 设置搜索窗口
    searchView.setOnQueryTextListener(
        new OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            mInSearchResultMode = true;
            updateAndFilterScriptList(query);
            mAdapter.notifyDataSetChanged();
            return false;
          }

          @Override
          public boolean onQueryTextChange(String query) {
            mInSearchResultMode = true;
            updateAndFilterScriptList(query);
            mAdapter.notifyDataSetChanged();
            return false;
          }
        });
    return true;
  }