我1.1.1在我的專案中使用 compose 版本。我正在這樣LocalRippleTheme使用
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Surface
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ClickableItemContainer(
rippleColor: Color = TealLight,
content: @Composable (MutableInteractionSource) -> Unit,
clickAction: () -> Unit
) {
val interactionSource = remember { MutableInteractionSource() }
CompositionLocalProvider(
LocalRippleTheme provides LgcRippleTheme(rippleColor),
content = {
Surface(
onClick = { clickAction() },
interactionSource = interactionSource,
indication = rememberRipple(true),
color = White
) {
content(interactionSource)
}
}
)
}
當我更新以撰寫版本時,1.2.1我收到了錯誤訊息Surface
Using 'Surface(() -> Unit, Modifier = ..., Shape = ..., Color = ..., Color = ..., BorderStroke? = ..., Dp = ..., MutableInteractionSource = ..., Indication? = ..., Boolean = ..., String? = ..., Role? = ..., () -> Unit): Unit' is an error. This API is deprecated with the introduction a newer Surface function overload that accepts an onClick().

uj5u.com熱心網友回復:
您必須洗掉該indication屬性:
Surface(
onClick = { clickAction() },
interactionSource = interactionSource,
color = White
) {
content(interactionSource)
}
M21.2.0 棄用了可點擊Surface功能,并引入了一個Surface接受onClick().
使用此 API,您無法定義修飾符indication內部定義的內容。clickable
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/512903.html
標籤:安卓科特林android-jetpack-compose机器人喷气背包
上一篇:被破壞的物體還在嗎?
