Lac*_*ook 6 android android-webview android-softkeyboard
我有一个webview,我在登录屏幕上手动显示键盘并专注于输入字段.
领域:
<input type="password" maxlength="4" pattern="[0-9]*" id="pin">
Run Code Online (Sandbox Code Playgroud)
聚焦和显示键盘:
webView.requestFocus(View.FOCUS_DOWN);
webView.loadUrl("javascript:document.getElementById('pin').focus();");
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
登录屏幕仅包含PIN样式代码字段,用户将在其中输入4位数字.问题是,默认情况下,它显示常规的alpha键盘,我希望它显示数字键盘.我已经看到很多使用EditText属性来控制键盘类型的例子
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
EditText.setInputType(InputType.TYPE_CLASS_PHONE); [select Input type as according to ur requirement]
mgr.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
但是有可能告诉键盘本身在WebView上显示什么类型或设置属性?
这条路线对我有用.创建一个子类WebView,并覆盖该方法onCreateInputConnection.WebView选择输入字段时会调用此方法,并且您可以自定义事件的处理方式.这是一个例子:
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
BaseInputConnection ic = new BaseInputConnection(this, true);
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER; // Tells the keyboard to show the number pad
return ic;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3446 次 |
| 最近记录: |