tôi trả lời bản thân mình. Theo bài đăng trên click home icon with espresso, Không thể chỉ định một Id
cho nút Trang chủ trong ActionBar, ít nhất là với phiên bản 7 của thư viện Hỗ trợ, vì vậy chúng tôi nên sử dụng "Điều hướng". Nhưng tại sao?
Đây là lý do nhờ vào lỗi dấu vết Espresso:
--------> ActionMenuView
{
id=-1, visibility=VISIBLE, width=144, height=168, has-focus=false,
has-focusable=true, has-window-focus=true, is-clickable=false,
is-enabled=true, is-focused=false, is-focusable=false,
is-layout-requested=false, is-selected=false, root-is-layout-requested=false,
has-input-connection=false, x=936.0, y=0.0, child-count=1
}
|
--------> ActionMenuItemView
{
id=2131296554, res-name=general, desc=, visibility=VISIBLE,
width=144, height=144, has-focus=false, has-focusable=true,
has-window-focus=true, is-clickable=true, is-enabled=true,
is-focused=false, is-focusable=true, is-layout-requested=false,
is-selected=false, root-is-layout-requested=false,
has-input-connection=false, x=0.0, y=12.0, text=, input-type=0, ime-target=false
}
|
--------> ImageButton
{
id=-1, desc=Navigate up, visibility=VISIBLE, width=168, height=168,
has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true,
is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false,
is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0
}
|
Hmm, thú vị. Tôi sử dụng cùng một mã để thực hiện tác vụ trên nút trang chủ: onView (withId (android.R.id.home)).thực hiện (nhấp()); Rất tiếc, chúng tôi vẫn đang sử dụng appcompat-v7: 20.0. Có lẽ điều này có liên quan đến thanh công cụ android mới? Bạn nhận được ID gì, nếu bạn sẽ kiểm tra chế độ xem bằng Màn hình Android? – Christopher
Rõ ràng, không có id với Thanh công cụ Android mới, thay vì chúng tôi sử dụng "Điều hướng": ( –