当用户再次单击时,我遇到了 Android 键盘从数字类型更改为默认 Alpha 的问题。在阅读了几篇关于无法在 webview 上将键盘的默认类型从字母更改为数字的帖子后,我遵循了以下过程。我创建了一个隐藏的 EditText 控件并从该控件更改了键盘类型,它工作正常,现在我得到了数字 SIP,并且所有按键都正确分派到 webview。但问题是,如果用户再次触摸 web 视图,则 InputMethodService 将键盘类型从数字更改为 alpha,并且我没有收到此事件的任何回调。
V/InputMethodService( 1764): CALL: onStartInput
我可以想到以下可能的解决方案,但似乎都没有。
1.有没有办法通过Webview上的InputMethodManager更改默认键盘类型?
2.如果已经显示了数字键盘,那么当用户再次触摸时,我们可以防止 InputMethodManager 更改为默认的字母键盘吗?
3.InputMethodService的onStartInput()方法有没有办法覆盖或接收回调?
InputMethodManager imm;
if (mWebEditText == null)
{
mWebEditText = new WebEditText(Common.mainActivity.getApplicationContext(),view.getView());
}
mWebEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
webEditTextPanel.addView(mWebEditText, lp);
mWebEditText.setVisibility(View.VISIBLE);
mWebEditText.requestFocus();
imm.showSoftInput(mWebEditText, 0);
WebEditText 类:
public class WebEditText extends EditText
{
//Pointer to the web view to dispatch the keys
View mWebView;
public WebEditText(Context context, View view)
{
super(context);
mWebView = view;
}
/**
* Override the dispatch key event to send the key events to the web view
* from the invisible Edit Text control
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
mWebView.dispatchKeyEvent(event);
return super.dispatchKeyEvent(event);
}