提问人:Devrath 提问时间:7/12/2022 更新时间:7/13/2022 访问量:966
在 android jetpack compose 中传递用于预览的单击操作
Passing a click action for preview in android jetpack compose
问:
我有什么:
- 我有一个带有按钮的 compose 类
- 我想在设计视图中查看预览
我面临的问题:
- 对于单击“如何作为对象传递”在我标记的行上 法典
这可能吗?
OnBoardingActionButton.kt
@OptIn(ExperimentalPagerApi::class)
@Composable
fun OnBoardingActionButton(
modifier : Modifier,
pagerState: PagerState,
onClick : () -> Unit
){
OnBoardingActionButtonContent(pagerState,onClick)
}
@OptIn(ExperimentalPagerApi::class)
@Composable
fun OnBoardingActionButtonContent(pagerState: PagerState, onClick: () -> Unit) {
Row(
modifier = Modifier.padding( horizontal = 40.dp),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.Center
) {
AnimatedVisibility(
modifier = Modifier.fillMaxWidth(),
visible = true
) {
Button(onClick = onccl) {
}
}
}
}
@OptIn(ExperimentalPagerApi::class)
@Preview(showBackground = true)
@Composable
fun PrevOnBoardingActionButton(){
val pagerState : PagerState = PagerState(2)
val onClick : () -> Unit -----------------------------> How to manage this
OnBoardingActionButtonContent(pagerState, onClick)
}
答:
1赞
Francesc
7/13/2022
#1
@OptIn(ExperimentalPagerApi::class)
@Preview(showBackground = true)
@Composable
fun PrevOnBoardingActionButton(){
val pagerState : PagerState = PagerState(2)
val onClick : () -> Unit = {}
OnBoardingActionButtonContent(pagerState, onClick)
}
评论