Show soft keyboard even though a hardware keyboard is connected

后端 未结 5 1713
野性不改
野性不改 2020-12-05 07:44

Is there any way to show software keyboard with USB keyboard connected (in my case RFID reader)?
I tried to force show it using InputManager (with these or similar para

5条回答
  •  鱼传尺愫
    2020-12-05 08:14

    according to this https://stackoverflow.com/a/24287780/2233069, I made working solution for Kiosk mode.

    boolean hardwareKeyboardPlugged=false;
    
    ....
    
    mEditText.setOnFocusChangeListener(this);//in onCreate()
    
    ....
    
    @Override
    public void onResume() {
        //protect from barcode scanner overriding keys
        hardwareKeyboardPlugged=(getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO);
    
        super.onResume();
    }
    
    ....
    
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus)
            if (hardwareKeyboardPlugged){
                //protect from barcode scanner overriding keys
                hardwareKeyboardPlugged=false;
                ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
                Toast.makeText(this, "USB device detected. Turn OFF hardware keyboard to enable soft keyboard!", Toast.LENGTH_LONG).show();
            }
    }
    

提交回复
热议问题