代码如下:
/**
* @param ud 测试的设备
* @param uiObject 要点击的元素
* @param steps 步长:值越大,长按动作的时间越长
* @throws UiObjectNotFoundException
*/
public void longClick(UiDevice ud, UiObject uiObject,int steps) throws UiObjectNotFoundException{
ud.swipe(uiObject.getBounds().centerX(), uiObject.getBounds().centerY(),
uiObject.getBounds().centerX(), uiObject.getBounds().centerY(), steps);
}
说明:
控件长按操作(按钮点击需要达到175ms才算长按)一般通过调节steps来控制时间:经过检测大于等于36才算长按,35还是单击(具体的需要自己通过steps来测试和调节);