我嘗試獲得一個按鈕,該按鈕在點擊時具有邊框半徑變化的酷炫效果(如在 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)
}
但是傳遞給的函式中的代碼onPress永遠不會執行。據我了解應該是,當點擊或按下按鈕時。我的錯誤在哪里,我誤解了檔案中的內容嗎?
uj5u.com熱心網友回復:
大多數 Compose 控制元件都有interactionSource用于此目的的引數。以下是您可以使用它的方法:
val interactionSource = remember { MutableInteractionSource() }
val pressed by interactionSource.collectIsPressedAsState()
Button(
onClick = {},
interactionSource = interactionSource,
) {
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/411105.html
標籤:
