【发布时间】:2014-12-17 14:36:20
【问题描述】:
我已启用主页按钮以返回上一个视图。简单地说,这样做:
getActionBar().setDisplayHomeAsUpEnabled(true);
我正在使用com.android.support:appcompat-v7:21.0.2 的最新版本。但是,当我使用下面的代码时,它不会抛出异常。
Espresso.onView(ViewMatchers.withId(android.R.id.home)).perform(ViewActions.click());
Espresso.onView(ViewMatchers.withId(R.id.home)).perform(ViewActions.click());
例外:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: is <2131296261> ...
【问题讨论】:
-
嗯,很有趣。我使用相同的代码对主页按钮执行操作:onView(withId(android.R.id.home)).perform(click());不幸的是,我们仍在使用 appcompat-v7:20.0.+。也许这与新的 android 工具栏有关?如果您将使用 Android Monitor 检查视图,您会检索什么 ID?
-
显然,新的 Android 工具栏没有 id,而不是我们使用“向上导航”:(。