如何禁用长按选项菜单键以调出键盘?

And*_*Dev 2 android

我已经在我的应用程序中创建了一个选项菜单,一切正常,但是当我在optionMenu按钮中长按一个inputKeyboard时,我怎么能禁用这个输入键盘出现在长按的选项菜单上...我有的代码就是. .

            public boolean onCreateOptionsMenu(Menu menu)
            {                   
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.menu, menu);
                return true;
            }

            public boolean onOptionsItemSelected(MenuItem item)
            {   

                switch (item.getItemId()) 
                {
                    case R.id.settingOpt:                           
                    Intent intent = new Intent(this, SettingForm.class);
                    this.startActivity(intent);  
                    break;         

                    case R.id.reminderOpt:                          
                    Intent intentR = new Intent(this, ReminderForm.class);
                    this.startActivity(intentR);   
                    break;

                    case R.id.helpOpt:                          
                    Intent intentH = new Intent(this, HelpForm.class);
                    this.startActivity(intentH);                                    
                    break;

                    case R.id.shareOpt:                             
                    Intent share = new Intent(android.content.Intent.ACTION_SEND);
                    share.setType("text/plain");
                    share.putExtra(Intent.EXTRA_SUBJECT, "Name of the thing to share");
                    share.putExtra(Intent.EXTRA_TEXT, "www.gmail.com");
                    startActivity(Intent.createChooser(share, "Title of the dialog that will show up"));
                    break;

                    default:

                    return super.onOptionsItemSelected(item);       
                }
                return true;
         }
Run Code Online (Sandbox Code Playgroud)

小智 13

我在Launcher2应用程序中找到解决问题的来源.
https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/Launcher.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean handled = super.onKeyDown(keyCode, event);


    // Eat the long press event so the keyboard doesn't come up.
    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    return handled;
}
Run Code Online (Sandbox Code Playgroud)