[英]Hide Virtual Keyboard in on Chrome on Android
有没有一种方法可以使用Selenium或ChromeOptions或ADB在Android上的Chrome上隐藏软键盘或虚拟键盘。 我进行了一些搜索,但是所有解决方案都好像键盘是打开的,然后按返回按钮将其隐藏。 但是有没有办法在我整个执行过程中禁止虚拟键盘弹出。
您可以使用以下方法隐藏键盘
public void hideKeyboard() {
// Check if no view has focus:
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
you can use this in oncreate
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
因此,我找到了一种使用adb shell ime
命令禁用和启用键盘的方法。 我写了一个Python脚本来启用/禁用所有键盘输入。
def enable_disable_android_input_methods(action):
p = subprocess.Popen(["adb", "devices"], stdout=subprocess.PIPE)
line = p.stdout.readline()
while line:
log.info(line)
if re.match("\S+\s+device", line):
break
line = p.stdout.readline()
else:
raise AssertionError, "Device not connected via USB"
p = subprocess.Popen("adb shell ime list -a".split(), stdout=subprocess.PIPE)
line = p.stdout.readline()
while line:
m = re.search("mId=(.*)", line)
if m:
if action.lower() == 'enable':
log.info("Enabling Keyboard layout: %s" % line)
cmd = "adb shell ime enable %s" % m.group(1)
else:
log.info("Disabling Keyboard layout: %s" % line)
cmd = "adb shell ime disable %s" % m.group(1)
q = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
out, err = q.communicate()
log.info(out)
line = p.stdout.readline()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.