如何在长按 ToolBar item(icon) android 时隐藏 Toast 消息的显示?

How to hide the display of Toast message, on long press of ToolBar item(icon) android?

有什么方法可以在长按 ToolBar 项后隐藏 toast 吗?

android 长按工具栏图标或图像按钮显示敬酒。

好的。我的问题解决了。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu, menu);
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            final View v = findViewById(R.id.action_settings);

            if (v != null) {
                v.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        return false;
                    }
                });
            }
        }
    });

    new Handler().post(new Runnable() {
        @Override
        public void run() {
            final View v = findViewById(R.id.action_search);

            if (v != null) {
                v.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        return false;
                    }
                });
            }
        }
    });

    return true;
}

并且您可以拥有 Toolbar 的可点击项目:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_search) {
        Toast.makeText(context,"action_search",Toast.LENGTH_SHORT).show();
        return true;
    }else if (id == R.id.action_settings) {
        Toast.makeText(context,"action_settings",Toast.LENGTH_SHORT).show();
        return true;
    }

    return super.onOptionsItemSelected(item);
}