Fox*_*tic 10 animation android kotlin android-jetpack-compose
我尝试获得一个按钮,该按钮在点击时具有边框半径变化的酷炫效果(就像在 Android 12 默认计算器应用程序中一样),同时还保持按钮的波纹效果。
我认为可行的是:
var pressed by remember { mutableStateOf(false) }
val borderRadius by animateDpAsState(
if (pressed) 10.0.dp
else 20.0.dp
)
val buttonTitle = "uniqueButton"
Button(
onClick = {
// some on click stuff
},
shape = RoundedCornerShape(borderRadius),
modifier = Modifier
.pointerInput(buttonTitle) {
detectTapGestures(
onPress = {
pressed = true
tryAwaitRelease()
pressed = false
}
)
}
) {
Text(text = buttonTitle)
}
Run Code Online (Sandbox Code Playgroud)
但传递给的函数内的代码onPress永远不会被执行。根据我的理解,应该是在点击或按下按钮时。我的错误在哪里,我是否误解了文档中的某些内容?
Phi*_*hov 10
大多数 Compose 控件都有interactionSource用于此目的的参数。使用方法如下:
val interactionSource = remember { MutableInteractionSource() }
val pressed by interactionSource.collectIsPressedAsState()
Button(
onClick = {},
interactionSource = interactionSource,
) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2758 次 |
| 最近记录: |