How to Trigger the soft keyboard?

后端 未结 3 440
借酒劲吻你
借酒劲吻你 2021-01-27 13:14

How can I trigger the software keyboard and add listeners to it\'s keys?

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 14:09

    Ive tried two options, but none of them worked in the emulator, as i said, i am trying to pop up soft keyboard on long-press menu:

    @Override
    
    public boolean onKeyLongPress(int keyCode, KeyEvent event)
    
    {
    
                if (keyCode == KeyEvent.KEYCODE_MENU)
            {
                 showSoftInput.getInputMethodList();
                 showSoftInput.toggleSoftInput(showSoftInput.SHOW_FORCED, 0);
    
                return true;
            }
            return super.onKeyLongPress(keyCode, event);
        }
    

    second option:

    View.OnLongClickListener mLongClickListener = new View.OnLongClickListener()
        {
    
            @Override
            public boolean onLongClick(View v)
            {
    
                Configuration config = RouteMapActivity.this.getResources()
                        .getConfiguration();
                if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
                {
                    InputMethodManager imm = (InputMethodManager) RouteMapActivity.this
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mapView, InputMethodManager.SHOW_IMPLICIT); // .SHOW_FORCED);
                }
                return false;
            }
    
        };
    

提交回复
热议问题