gpt4 book ai didi

android - 是否可以在 uiautomator 中滑动打开/关闭抽屉导航

转载 作者:行者123 更新时间:2023-11-29 15:14:38 25 4
gpt4 key购买 nike

有没有人能做到这一点。 UiScrollable、swipeLeft 和 swipeRight 似乎对其没有任何影响。我正在使用带有最新 api 的 Nexus 5 模拟器。有人成功过吗?

最佳答案

TL;DR:使用 ActionBarDrawerToggle constructor 中设置的内容描述


  1. 设置抽屉导航时,设置一个 ActionBarDrawerToggle,其中包含用于打开和关闭的内容说明。

// Open drawer content description for accessibility
private static final String CONTENT_DESCRIPTION_OPEN_DRAWER = "Open drawer";

// Close drawer content description for accessibility
private static final String CONTENT_DESCRIPTION_CLOSE_DRAWER = "Close drawer";

private void setUpNavigationDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, CONTENT_DESCRIPTION_OPEN_DRAWER, CONTENT_DESCRIPTION_CLOSE_DRAWER);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
  1. 在您的 UiAutomatorTestCase 中,要打开/关闭抽屉,请根据第 1 步中定义的打开/关闭内容描述找到 UI 对象,然后单击它。

// Open drawer content description for accessibility
private static final String CONTENT_DESCRIPTION_OPEN_DRAWER = "Open drawer";

// Close drawer content description for accessibility
private static final String CONTENT_DESCRIPTION_CLOSE_DRAWER = "Close drawer";

private void openNavDrawer() throws UiObjectNotFoundException {
findViewByContentDescription(CONTENT_DESCRIPTION_OPEN_DRAWER).click();
}
private void closeNavDrawer() throws UiObjectNotFoundException {
findViewByContentDescription(CONTENT_DESCRIPTION_CLOSE_DRAWER).click();
}
private UiObject findViewByContentDescription(String description) {
return new UiObject(new UiSelector().description(description));
}

警告:如果您使用 Material design approach对于抽屉导航(抽屉在 Topbar 顶部和状态栏后面打开),“汉堡包”图标将绘制在抽屉后面,使 closeDrawer() 方法不起作用。作为解决方法,您可以只选择在抽屉菜单中打开的部分;这将关闭抽屉并显示打开它之前的相同部分。

关于android - 是否可以在 uiautomator 中滑动打开/关闭抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25898852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com