Tag: onlongclicklistener

如何在菜单项上捕获长按?

我有一个典型的菜单,我想为其中一个项目设置onLongClickListener 。 换句话说,我希望这个项目能够执行正常的onOptionsItemSelected函数,以及长按function。 MenuItem item; item = menu.findItem(android.R.id.home); item.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { Context context = getApplicationContext(); CharSequence text = “Long Press”; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); return true; } });