我有一个简单的Fragment像这样:
class SomeFragment : DaggerFragment() {
...
}
Run Code Online (Sandbox Code Playgroud)
现在我想Fragment用它来测试这个FragmentScenario
class LoginFragmentTest {
@Test
fun test() {
launchFragmentInContainer<SomeFragment>()
onView(withId(R.id.someButton))
.check(matches(isDisplayed()))
}
}
Run Code Online (Sandbox Code Playgroud)
但每次我尝试测试时总是:
java.lang.IllegalArgumentException:找不到 <...SomeFragment> 的注入器
我怎样才能正确运行测试?有人可以帮我吗?
我希望我的按钮有圆角,例如:
要在 Android 中使用材质主题实现此目的,请将:设置shapeAppearanceSmallComponent为有一个rounded角。
但设置shapeAppearanceSmallComponent也会影响所有其他组件,例如EditText现在它们也被舍入。
因此,我没有将其设置为shapeAppearanceSmallComponent,而是创建了一个shapeMaterialOverlay. 将此覆盖设置为 abuttonStyle并将主题中的此按钮样式设置为默认按钮样式。
它有效,但仅适用于默认按钮。如果我需要TextButton这样的:
<Button
...
style="@style/Widget.MaterialComponents.Button.TextButton"/>
Run Code Online (Sandbox Code Playgroud)
不会TextButton被舍入。因此,作为一种解决方法,我创建了MyTextButton从那里延伸TextButton并设置shapeOverlay在那里的样式。
所以现在如果我需要一个TextButton,我会这样做:
<Button
...
style="@style/Widget.MaterialComponents.Button.MyTextButton"/>
Run Code Online (Sandbox Code Playgroud)
反而。
我必须对所有其他按钮类型执行此操作。我想知道这种方法是否正确,如果不正确,有人可以指导我如何正确执行此操作吗?
非常感谢。
android android-button material-design material-components material-components-android
因此 DataBinding 现在可以在其绑定中使用 LiveData。作为其中的一部分,我们还必须将生命周期设置为数据绑定,如下所示:
SampleLayoutBinding binding = DataBindingUtil.inflate(this, R.layout.sample_layout)
binding.setLifeCycleOwner(this)
Run Code Online (Sandbox Code Playgroud)
我的问题是在 recyclerview 中设置这个生命周期所有者的正确方法是什么?或者更恰当地说,在 recyclerview 中使用数据绑定时,我们是否需要设置 LifeCyclerOwner?
我正在尝试Ktor通过转换一些当前正在使用的现有项目Retrofit。
虽然我可以轻松地将请求转换为类似的内容:
client.get {
url("$BASE_URL/something/somepage/another")
}
Run Code Online (Sandbox Code Playgroud)
$BASE_URL每次都添加到所有路径似乎很乏味。在改造中,我们可以简单地执行以下操作:
Retrofit.Builder()
.baseUrl(BASE_URL)
.create(SomeServiceClass::class.java)
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用defaultRequest和设置BASE_URL那里,但显然你只能设置url.host而不是整个basePath.
有没有办法在 中做同样的事情Ktor?或者如果没有,处理这个问题的最佳做法是什么?