我正在编写一个Ionic应用程序,将用于医疗行业的后勤目的 .
将用于此应用程序的设备具有内置条形码扫描仪,并在Android 4.1.1上运行 .
此扫描器在输入字段中输入数据,然后按"enter"键提交数据 . 由于在某些情况下扫描仪是我的"keyboard",我想在输入焦点或点击时隐藏键盘 .
我使用离子键盘cordova插件编写了以下指令:
directives.directive("showKeyboard", [
function() {
var linkFn = function(scope, element, attrs) {
console.log(scope);
console.log(element);
console.log(attrs);
if(!window.cordova || !window.cordova.plugins.Keyboard) return; // Check for cordova keyboard plugin
if(element[0].nodeName.toLowerCase() != 'input') return; // check for input
if(attrs.type.toLowerCase() != 'password' && attrs.type.toLowerCase() != 'text') return; // check for type of input
element.bind("focus click",
function(e) {
e.preventDefault();
if(scope.$eval(attrs.showKeyboard)){
console.log('show')
window.cordova.plugins.Keyboard.show();
}
else {
console.log('hide');
cordova.plugins.Keyboard.close();
}
}
);
};
var keyboardDirective = {
restrict : 'A',
link: linkFn
};
return keyboardDirective;
}
]);
功能似乎有效 . 只有键盘不会关闭,似乎被设备“强制”打开 .
有什么建议?
1 回答
我尝试使用你的指令来抑制默认的原生键盘以显示另一个键盘,并发现我必须使用100ms的$ timout才能调用hide来关闭键盘(以解决竞争条件) . 但是,它会产生闪烁伪影,因此它不是最佳解决方案 . 我还没有尝试的另一个想法是通过一个可以调用的自定义插件在Java中压制他们的Android键盘,