В этом следующем примере я могу получить кнопку вкладки навигации на панели действий (нативная или ActionBarSherlock). Затем я нажимаю на них с помощью TouchUtils.clickView ():
try {
// Trying to get the ActionBar view '@id/android:action_bar_container' dynamically
int resId =
a.getResources().getIdentifier("action_bar_container", "id", "android");
View actionBarContainer = a.findViewById(resId);
// The class 'com.android.internal.widget.ActionBarContainer' must be in
// the classpath of this test project to be able to call
// the method 'getTabContainer' at runtime
Method getTabContainer =
com.android.internal.widget.ActionBarContainer.class.getMethod("getTabContainer",
(Class<?>[]) null);
HorizontalScrollView tabContainer =
(HorizontalScrollView) getTabContainer.invoke(actionBarContainer, (Object[]) null);
return ((ViewGroup) tabContainer.getChildAt(0)).getChildAt(tabIndex);
} catch (Exception e) {
// Trying with SherlockActionBar
com.actionbarsherlock.internal.widget.ActionBarContainer actionBarContainer =
(com.actionbarsherlock...) a.findViewById(R.id.abs__action_bar_container);
HorizontalScrollView tabContainer =
(HorizontalScrollView) actionBarContainer.getTabContainer();
return ((ViewGroup) tabContainer.getChildAt(0)).getChildAt(tabIndex);
}
}