简体   繁体   中英

Is it possible to open virtual keyboard forcefully?

Is it possible to popup virtual keyboard when some command is being received from server? I am trying to call focus on text area but soft keyboard is not coming. I agree that for keyboard to popup, user event is required. Is there any way to show virtual keyboard forcefully? I am talking about web app inside Android chrome browser.

You can do this by calling focus() then click() on the input, but, as you say, only when the script is initiated by user input. My current answer, having spent a day fiddling, is that there is no way to get around this.

This question may help you: Showing Android's soft keyboard when a field is .focus()'d using javascript

In your case you could try to have a hidden text input field on your page and trigger a click event on it when the command is received from the server.

EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

May this will help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM