[英]How to programmatically open Android soft keyboard according to the html input type in android webview
我想在頁面加載時顯示android軟鍵盤並以編程方式聚焦輸入字段。
$('#field').focus();
就我研究而言,除了用戶生成的事件(如click事件)之外,這不可能完成。
所以我嘗試了一種解決方法來聚焦輸入字段,並使用此代碼手動顯示Android鍵盤。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(myWebView.getWindowToken() , InputMethodManager.SHOW_IMPLICIT , 0);
鍵盤成功顯示,輸入字段也正在獲得焦點。 但問題是,它只顯示標准鍵盤。 我想根據指定的輸入類型顯示鍵盤。
就像輸入字段是:
<input type="number" id="field" name="field"/>
上面的解決方法是顯示標准文本鍵盤,但我想根據輸入字段中的類型顯示數字鍵盤。
在我找到解決方案之前,我已經搜索了很長時間。
添加這個:
imm.restartInput(view);
在showSoftInput之后。
這將“重新計算”關於聚焦輸入的鍵盤類型
嘗試這個:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.