我怎样才能捕捉到一个菜单项长preSS?捉到、菜单项、preSS

2023-09-05 05:12:39 作者:______冷色

我有一个典型的菜单,我想设置一个 onLongClickListener 的项目之一。换句话说,我希望这个项目执行这是正常的 onOptionsItemSelected 的功能,以及,一个长preSS功能。

 菜单项项目;
    项目= menu.findItem(android.R.id.home);

item.setOnLongClickListener(新OnLongClickListener(){
        公共布尔onLongClick(视图v){
            上下文的背景下= getApplicationContext();
            CharSequence的文字=龙preSS;
            INT持续时间= Toast.LENGTH_SHORT;

            吐司面包= Toast.makeText(背景,文本,持续时间);
            toast.show();
            返回true;
        }

    });
 

解决方案

使用了则findItem 方法对菜单来让您的看法,并设置长按听众对每个视图。

如何设置WordPress导航菜单的样式

I have a typical menu and I'm wanting to set a onLongClickListener for one of the items. In other words, I want this item to perform it's normal onOptionsItemSelected function, as well as, a long press 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;
        }

    });

解决方案

Use the findItem method on Menu to get your views, and set your long click listener on each view.