How to programmatically open an Android keyboard according to the html input type in an Android web browser

I want to show the soft keyboard for Android to load the page and programmatically focus the input field.

$('#field').focus();

As far as I’ve researched, this is impossible to do, except for events created by the user, such as the click event.

So, I tried a workaround to focus the input field and show the Android keyboard manually using this code.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInputFromWindow(myWebView.getWindowToken() , InputMethodManager.SHOW_IMPLICIT , 0);

The keyboard is displayed successfully, and the input field also focuses. But the problem is that it only shows a standard keyboard. I want to show the keyboard according to the specified input type.

As if the input field:

<input type="number" id="field" name="field"/> 

A standard text keyboard is displayed above the workaround, but I want to show the numeric keypad according to the type in the input field.

+4
2

, .

:

imm.restartInput(view); 

showSoftInput.

"" ,

+1

:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
-1

All Articles