如何使用robotium单击软键盘的完成按钮?

时间:2012-06-22 10:09:23

标签: android robotium soft-keyboard

我需要在编辑文字文本中输入一些文字,之后必须点击软键盘完成按钮。为此,我使用了以下代码

solo.sendKey(Solo.ENTER);

solo.clickOnText("Done");

但它不起作用。我可以使用 robotium 点击软键盘中的完成按钮吗?

4 个答案:

答案 0 :(得分:2)

Robotium 5.0.1有一个方法pressSoftKeyboardNextButton,定义为:

public void pressSoftKeyboardNextButton(){
  final EditText freshestEditText = viewFetcher.getFreshestView(viewFetcher.getCurrentViews(EditText.class));
  if(freshestEditText != null){
    inst.runOnMainSync(new Runnable()
    {
      public void run()
      {
        freshestEditText.onEditorAction(EditorInfo.IME_ACTION_NEXT); 
      }
    });
  }
}

可以使用相同的方法使用EditorInfo.IME_ACTION_DONE调用“完成”按钮

答案 1 :(得分:1)

实际上,你必须做solo.go后退()来关闭键盘。

答案 2 :(得分:0)

你试过吗?

solo.sendKey(16);

实际上,

<强> KeyEvent.FLAG_EDITOR_ACTION

public static final int FLAG_EDITOR_ACTION

This mask is used for compatibility, to identify enter keys that are coming from an IME whose enter key has been auto-labelled "next" or "done". This allows TextView to dispatch these as normal enter keys for old applications, but still do the appropriate action when receiving them.
Constant Value: 16 (0x00000010)

答案 3 :(得分:0)

无需按完成按钮继续操作。在编辑文本中输入文本后,您可以提供下一条指令,例如solo.clickOnText("submit")或其他需要的内容。