我有一个网页视图,其中我有3种输入类型的Android web视图从数字输入类型swtiching到密码输入类型
- 数
- 文本
- 密码
当我从数切换到文本输入字段,qwerty键盘按预期打开。当我从文本切换到密码时,qwerty键盘根据需要打开,没有任何建议。但问题是,当我从数字切换到密码输入字段数字键盘打开,但我希望它是QWERTY,以便我可以在密码字段中默认输入字母
我已经这样做来覆盖我的webview onCreateInputConnection。下面的代码与此问题无关,因为此代码被用作在数字键盘上显示小数点键的解决方案,该键在默认情况下不存在。但我知道,这里需要改变让我的问题解决了的东西
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
super.onCreateInputConnection(outAttrs);
if ((outAttrs.inputType & InputType.TYPE_CLASS_NUMBER) == InputType.TYPE_CLASS_NUMBER)
{
outAttrs.inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
}
else
{
outAttrs.inputType |=InputType.TYPE_CLASS_TEXT;
InputConnection connection = super.onCreateInputConnection(outAttrs);
return connection;
}
return new ExtendedInputConnection(this,false);
}
这是ExtendedInputConnection类仅供参考。在这里,我已经添加方法,以便在发送了退格keydown事件,并且可以通过JQuery的
捕获public class ExtendedInputConnection extends BaseInputConnection implements InputConnection{
public ExtendedInputConnection(View targetView, boolean fullEditor) {
super(targetView, fullEditor);
// TODO Auto-generated constructor stub
}
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
// in latest Android, deleteSurroundingText(1, 0) will be called for backspace
if (beforeLength == 1 && afterLength == 0) {
// backspace
return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
}
但如何添加这些标签为第一种情况我已添加标签但密码我怎么知道编辑器信息有密码作为输入类型,以便我可以设置InputType.TYPE_NUMBER_VARIATION_PASSWORD – 2014-09-29 06:41:11
首先抱歉,你说你想要密码作为文本,我采取了错误的标志。其次,我不明白你的意思。你必须检查EditorInfo的'InputType'以应用于'EditText'还是有更多的“外部条件”?你可以多开发一些你想达到的东西吗? – zozelfelfo 2014-09-29 06:46:53
我只想在我的onCreateInputConnection中知道webview返回什么类型的输入,在if条件下,就像我对数字类型字段所做的那样。然后设置适当的标志,如果输入类型是密码。总之,我想知道输入类型是否是密码,如果是我想设置适当的标志 – 2014-09-29 06:52:06