2017-03-15 247 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);