是否可以在按下某个按钮后跟踪哪个活动被打开?
我有一个测试,当点击/按下按钮时,它会向服务器发送一个请求.直到发送请求的时间,它会打开一个活动.为了验证测试的成功执行,我需要检查什么是打开的Activity.
我的测试示例:
检查Espresso中打开的Intent ---
private void startTest() {
recreateAuthData(InstrumentationRegistry.getTargetContext(), "d78269d9-9e00-4b8d-9242-815204b0a2f6", "3f32da21-914d-4adc-b6a1-891b842a2972");
InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
Context.MODE_PRIVATE).edit().putInt(ActivitySplashScreen.PROPERTY_APP_VERSION, ActivitySplashScreen.getAppVersion(InstrumentationRegistry.getTargetContext())).commit();
InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
Context.MODE_PRIVATE).edit().putString(ActivitySplashScreen.PROPERTY_REG_ID, "testKey").commit();
mActivityRule.launchActivity(setIntent());
// inputPinCode("2794");
}
@Test
public void testIdent() {
startTest();
onView(withText("???")).perform(click());
putDelay(500);
onView(withId(R.id.get_pro)).perform(click());
onView(withText("??????????? ?? ?????????? ??????")).perform(click());
putDelay(500);
closeSoftKeyboard();
onView(withId(R.id.btn_goto_passport)).perform(click());
onView(withHint("????? ? ????? ????????")).perform(replaceText("9894657891"));
onView(withHint("???? ?????? ????????")).perform(replaceText("17032014"));
onView(withHint("???? ????????")).perform(replaceText("31091994"));
onView(withHint("?????")).perform(replaceText("54665285919"));
putDelay(500);
Log.d("TestWidget", hasComponent(hasShortClassName("ActivityMain")).toString());
onView(withId(R.id.btn_next)).perform(click());
// some code which check which activity is display now
putDelay(500);
}
Run Code Online (Sandbox Code Playgroud) 如何在这张照片上制作工具栏:
这是第一个状态
这是第二个州
我使用CalendarView的折叠工具栏.我将这个库用于CalendarView com.prolificinteractive:material-calendarview:1.0.1这是我的xml代码:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/appbar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_showOtherDates="all"
app:mcv_selectionColor="#00F">
</com.prolificinteractive.materialcalendarview.MaterialCalendarView>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:background="@color/primary_color"
android:titleTextColor="@color/text_color"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nickname_profile"
android:text="@string/nickname"
android:textColor="@color/text_color"
android:textSize="24sp"
android:layout_gravity="bottom|center"
android:layout_marginBottom="20dp"
android:layout_marginRight="40dp"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/general_fragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
第二个问题:如何在没有滚动的情况下单击打开工具栏?
我有浮动操作菜单,我使用这个库来制作它'com.github.clans:fab:1.6.1'
现在我需要在点击它时更改我的图标.我有一些图标,当我点击菜单时,我需要将其转换为另一个图标(图标加).可能吗?这是我的xml:
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/menu3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
fab:menu_icon="@drawable/ic_float_cards"
android:layout_margin="16dp"
fab:menu_animationDelayPerItem="0"
fab:menu_colorNormal="@color/event_background"
fab:menu_colorPressed="@color/fab_colorPressed"
fab:menu_colorRipple="@color/fab_colorRipple"
fab:menu_labels_maxLines="2"
fab:menu_labels_ellipsize="end">
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_dial_fill"
fab:fab_label="?????????"
style="@style/MenuButtonsSmall.Green" />
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_dial_pay"
fab:fab_label="????????"
style="@style/MenuButtonsSmall.Yellow" />
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_dial_outcome"
fab:fab_label="?????????"
style="@style/MenuButtonsSmall.Red" />
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_dial_income"
fab:fab_label="?????? ????????"
style="@style/MenuButtonsSmall.DarkPink" />
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_dial_send"
fab:fab_label="?????????"
style="@style/MenuButtonsSmall.Purple" />
</com.github.clans.fab.FloatingActionMenu>
Run Code Online (Sandbox Code Playgroud)
在第一个图标是ic_float_cards,但当我点击它应该是ic_float_cross
如果你有一些想法告诉我,请)
我有使用coordinatlayout,AppBarLayout和CollapsingToolbarLayout的布局.我想写一个点击列表中最后一项的测试.我滚动列表直到结束,然而,espresso中隐藏了所需的项目.要滚动列表,我使用:
onView(withId(R.id.widget_recycler_view)).perform(RecyclerViewActions.scrollToPosition(3));
要隐藏,滚动工具栏,我尝试了以下代码:
onView(withId(R.id.coordinator_layout)).perform(swipeUp());
onView(withId(R.id.toolbar)).perform(swipeUp());
Run Code Online (Sandbox Code Playgroud)
但是这段代码只隐藏了工具栏的一半,但这还不够.这是布局的代码:
<?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 …Run Code Online (Sandbox Code Playgroud)