小编Mar*_*515的帖子

如何在android操作栏中隐藏菜单项?

我的目标是隐藏操作栏中的一个菜单项,并在单击菜单项后显示另一个菜单项.在我的申请中,我正在使用Toolbar.我已经找了很多其他问题而没找到我需要的东西.任何帮助将不胜感激.我尝试下面的代码,但点击后这会崩溃应用程序.

public boolean onOptionsItemSelected(MenuItem item) {
    final SwipeRefreshLayout mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    switch (item.getItemId()) {
        case R.id.action_next:
            //code
            MenuItem secondItem = (MenuItem) findViewById(R.id.action_next);
            secondItem.setVisible(false);
            return true;

        case R.id.action_previous:
            //code
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Run Code Online (Sandbox Code Playgroud)

android toolbar android-actionbar

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-actionbar ×1

toolbar ×1