当用户第二次触摸网络视图时,阻止InputMethodService将数字键盘更改为Alpha



当用户再次单击时,Android键盘从数字类型更改为默认Alpha时,我遇到了问题。在阅读了几篇关于无法在网络视图中将键盘的默认类型从字母更改为数字的帖子后,我遵循了以下过程。我已经创建了一个隐藏的EditText控件,并从该控件更改了键盘类型,它工作得很好,现在我得到了Numeric SIP,所有按键都正确地分配到了Web视图。但问题是,如果用户再次触摸网络视图,InputMethodService会将键盘类型从数字更改为字母,并且我不会收到任何对此事件的回调。

V/InputMethodService( 1764): CALL: onStartInput

我能想到以下可能的解决方案,但似乎都不起作用。

1.有没有办法通过网络视图上的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);       
}

您可以在这里从您在web视图中显示的HTML代码中进行操作。将EditText(文本框)的输入类型更改为数字。

 <input type="number" placeholder="Text box lable" id="Text box id" required value="defautvalue" />

编辑:

EditText e = new EditText(getApplicationContext());
            e.setInputType(InputType.TYPE_CLASS_NUMBER);
            appView.addView(e);

你能像我那样添加编辑文本吗。它在我的应用程序中运行良好

最新更新