(Robotium) Action bar up/home button click

☆樱花仙子☆ 提交于 2019-11-30 22:58:47

I use this function:

public void clickOnActionBarHomeButton(Solo solo) {
    View homeView = solo.getView(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home : R.id.home);
    solo.clickOnView(homeView);
}

Maybe it's not a perfect decision, but it works.

In our application Home button eventually calls NavUtils.navigateUpFromSameTask. When using

solo.clickOnActionBarHomeButton();

to click Home button, it doesn't work. However, I have noticed that solo.clickOnScreen clicks on Home button reliably. So we use this method instead of solo.clickOnActionBarHomeButton:

protected void clickOnHome() {
    solo.clickOnScreen(50, 50); //usually hits Home button
}

You can click the Up/Home button (that is the first ImageButton element in the activity) by using the following code:

solo.clickOnImageButton(0);
instrumentation.waitForIdleSync();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!