2017-03-15 234 views
0

使用Selenium或ChromeOptions或ADB,我可以在Android上的Chrome上隐藏软键盘或虚拟键盘吗? 我做了一些搜索,但所有的解决方案都像是如果键盘打开,然后按回按钮隐藏它。 但是有没有办法在整个执行过程中禁用虚拟键盘弹出。在Android上使用Chrome浏览器隐藏虚拟键盘

回答

0

于是我找到了一种方法来禁用和使用adb shell ime命令使keybords。我写了一个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() 
0

您可以使用下面的方法来隐藏键盘

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); 
     } 
    } 
+0

这又是如果keybord存在隐藏,我正在寻找一种方式,使键盘根本不会弹出 –

0
you can use this in oncreate 

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);