如何从片段场景中获取片段实例
How to get fragment instance from Fragment Scenario
在我的测试用例中,我想获取我在片段场景中启动的片段的视图,如下所示:
val scenario = launchFragment<MyFragment>()
在 MyFragment
中,我有一个方法 rootView
returns 片段的绑定视图。在我的测试中,我想获取根视图并将其保存在另一个字段中。这是我试过的
val rootView: ViewGroup? = null
val scenario = launchFragment<MyFragment>()
scenario.onFragment { fragment -> fragment.rootView {
rootView = fragment.rootView
}
如何保存片段场景中的视图?
一个迟到的答案,但以防其他人需要它:
val root: View? = null
val scenario = launchFragment<MyFragment>()
scenario.onFragment { fragment ->
root = fragment.view?.rootView
}
在我的测试用例中,我想获取我在片段场景中启动的片段的视图,如下所示:
val scenario = launchFragment<MyFragment>()
在 MyFragment
中,我有一个方法 rootView
returns 片段的绑定视图。在我的测试中,我想获取根视图并将其保存在另一个字段中。这是我试过的
val rootView: ViewGroup? = null
val scenario = launchFragment<MyFragment>()
scenario.onFragment { fragment -> fragment.rootView {
rootView = fragment.rootView
}
如何保存片段场景中的视图?
一个迟到的答案,但以防其他人需要它:
val root: View? = null
val scenario = launchFragment<MyFragment>()
scenario.onFragment { fragment ->
root = fragment.view?.rootView
}