浓咖啡工具栏如何关闭 [英] How close toolbar Espresso

查看:56
本文介绍了浓咖啡工具栏如何关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有coordinatlayout,AppBarLayout和CollapsingToolbarLayout的布局.我想编写一个单击列表中最后一项的测试.我在列表中滚动直到结尾,但是所需的项目从浓缩咖啡中隐藏了.要在列表中滚动,我使用:
onView(withId(R.id.widget_recycler_view)).perform(RecyclerViewActions.scrollToPosition(3)); 为了隐藏,滚动浏览工具栏,我尝试了以下代码:

I have layout with coordinatlayout, AppBarLayout and CollapsingToolbarLayout. I want to write a test that clicks on the last item in the list. I scroll through the list until the end, however, the desired item is hidden from the espresso.To scroll through the list, I use:
onView(withId(R.id.widget_recycler_view)).perform(RecyclerViewActions.scrollToPosition(3)); To hide, scroll through the toolbar, I tried the following code:

onView(withId(R.id.coordinator_layout)).perform(swipeUp());
onView(withId(R.id.toolbar)).perform(swipeUp());

但是此代码仅将工具栏隐藏一半,但这还不够.这是布局的代码:

But this code hides the toolbar only half, but it's not enough. Here is the code of the layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/coordinator_layout"
        >

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:background="?attr/colorPrimary">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways"
                android:fitsSystemWindows="true">

                <android.support.v7.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:id="@+id/toolbar"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:layout_gravity="top"
                    app:layout_collapseMode="parallax"
                    android:background="?attr/colorPrimary"
                    >
                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <com.makeramen.RoundedImageView
                            style="@style/AvatarImage.MainActivity"
                            android:id="@+id/iv_avatar"
                            android:layout_marginRight="18dp"/>

                        <com.akbars.bankok.views.custom.TextViewFonted
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textAppearance="?android:attr/textAppearanceSmallInverse"
                            android:layout_toRightOf="@id/iv_avatar"
                            android:id="@+id/name"
                            android:textSize="12sp"
                            app:customFont="Roboto-Medium.ttf"
                            android:textColor="@android:color/white"/>

                        <com.akbars.bankok.views.custom.TextViewFonted
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:textSize="16sp"
                            app:customFont="Roboto-Light.ttf"
                            android:id="@+id/tv_balance"
                            android:layout_toRightOf="@id/iv_avatar"
                            android:layout_below="@id/name"
                            android:textColor="@android:color/white"/>
                    </RelativeLayout>
                    <ProgressBar
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/progressBarStyleSmall"
                        android:id="@+id/progress_bar"
                        android:visibility="gone"
                        android:layout_marginLeft="20dp"/>
                </android.support.v7.widget.Toolbar>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
        <com.akbars.bankok.views.custom.SwipeEnableViewPager
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/main_view_pager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_marginBottom="@dimen/tab_bar_layout_height"/>

        <com.akbars.bankok.views.custom.CustomTabLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/bottom_navigation_tab"
            android:id="@+id/tabs"
            app:tabMode="fixed"
            app:tabIndicatorColor="@android:color/transparent"
            android:layout_gravity="center_horizontal|bottom"
            style="@style/MyCustomTabLayout"
            android:background="@android:color/white"
            android:elevation="10dp"
            />
    </android.support.design.widget.CoordinatorLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/shadow"
        android:background="@color/shadow"
        android:visibility="invisible"
        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        style="@style/FABButton"
        android:src="@drawable/ic_import_export_white_24dp"
        app:backgroundTint="?attr/colorPrimary"
        />
    <include layout="@layout/fab_layout" />
</FrameLayout>

我附上我的考试.如果您滚动指针,则可以进行:) 但这是必要的自动化过程.

Just I attach my test. If you scroll through the hands, it works :) But it is necessary robotized process.

    @Test
    public void addNewPhone(){
        onView(withId(R.id.widget_recycler_view)).perform(RecyclerViewActions.scrollToPosition(3));
        onView(withId(R.id.coordinator_layout)).perform(swipeUp());
        putDelay(2500);
        onView(withId(R.id.layout_add_phone)).perform(click());
        onView(withId(R.id.edit_letay_phone)).perform(replaceText("9586222922"));
        closeSoftKeyboard();
        onView(withText(R.string.add)).perform(click());
        closeSoftKeyboard();
        onView(withId(R.id.edit_code_letay_phone)).perform(replaceText("52461"));
        onView(withId(R.id.bt_code_request)).perform(click());
    }

我的问题是:滚动列表或布局时如何完全隐藏工具栏?

推荐答案

我在测试中使用以下自定义视图操作:

I use the following custom view action in my tests:

 public static ViewAction collapseAppBarLayout() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(AppBarLayout.class);
        }

        @Override
        public String getDescription() {
            return "Collapse App Bar Layout";
        }

        @Override
        public void perform(UiController uiController, View view) {
            AppBarLayout appBarLayout = (AppBarLayout) view;
            appBarLayout.setExpanded(false);
            uiController.loopMainThreadUntilIdle();
        }
    };
}

以及用法:

onView(withId(R.id.app_bar_layout)).perform(CustomViewActions.collapseAppBarLayout());

请记住,您需要在设备设置中禁用动画,否则,Espresso不会等待其完全折叠后再继续下一步.

Keep it mind, you need to have animations disabled in the device settings, otherwise, Espresso will not wait for it to fully collapse before proceeding to the next step.

这篇关于浓咖啡工具栏如何关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆