我想在 Jetpack Compose 中实现MaterialButtonToggleGroup。该组件如下所示(图片取自此处):
到目前为止,我得到了以下结果:
请注意,存在垂直蓝色边框旁边的垂直灰色边框。在原作中,要么同时出现彩色边框,要么同时出现灰色。为了看得更清楚,看一下这张带有超厚边框的图像:
如何实现两个按钮之间不存在垂直边框?我当前的代码如下所示:
val cornerRadius = 8.dp
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Spacer(modifier = Modifier.weight(1f))
items.forEachIndexed { index, item ->
OutlinedButton(
onClick = { indexChanged(index) },
shape = when (index) {
// left outer button
0 -> RoundedCornerShape(topStart = cornerRadius, topEnd = 0.dp, bottomStart = cornerRadius, bottomEnd = 0.dp)
// right outer button
items.size - 1 -> RoundedCornerShape(topStart = 0.dp, topEnd = cornerRadius, bottomStart = 0.dp, bottomEnd = cornerRadius) …
Run Code Online (Sandbox Code Playgroud) android modifier android-button kotlin android-jetpack-compose
我想在我的应用程序中提供一些自动填充功能(电子邮件和密码),该功能完全使用 Jetpack compose 编写。我偶然发现了这篇博文和我都尝试过的演示代码。不幸的是,与文本字段交互时我无法收到任何弹出窗口。
修改我的代码后,我最终使用了提供的演示。一个最小的示例如下所示(ExplicitAutofillTypesDemo
可组合项取自上面提到的演示代码,没有任何修改):
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ExplicitAutofillTypesDemo()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我缺少什么?我需要在其他地方启用它吗?官方撰写自动填充文档不是很有帮助。我只想在触摸文本字段时获得自动填充弹出窗口,如上面的博客文章中所示。
我目前正在使用 Kotlin 协程和流程。在我的场景中, aMutableStateFlow
代表连接状态 ( CONNECTING, CONNECTED, CLOSING, CLOSED
)。也可以登录、注销和再次登录。
为了进一步使用连接,我必须检查状态并等到它是CONNECTED
. 如果已经是CONNECTED
,我可以继续。如果没有,我必须等到状态达到CONNECTED
. 该connect()
调用不会返回通过可更新回调马上,结果被传播MutableStateFlow
。我目前的想法是做以下事情:
connect()
if (connectionState.value != State.CONNECTED) { // connectionState = MutableStateFlow(State.CLOSED)
suspendCoroutine<Boolean> { continuation ->
scope.launch { // scope = MainScope()
connectionState.collect {
if (it == State.CONNECTED) {
continuation.resume(true)
}
}
}
}
}
// continue
Run Code Online (Sandbox Code Playgroud)
由于我对这个主题还很陌生,我不知道这是否是一种好的做法,而且我也无法在 Kotlin 文档中找到更合适的概念。有没有更好的方法来做到这一点?