[英]Android Jetpack Compose - Floating Action Button of custom image
[英]Android Floating action button, how to use it based on screen jetpack compose
我使用 scaffold jetpack compose 為不同的屏幕設置了浮動操作按鈕,我如何知道當前屏幕點擊了 FAB 以執行特定操作。 因為對於每個屏幕,操作都是不同的。
@OptIn(ExperimentalMaterial3Api::class)
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun AppLayout(
bottomBar: @Composable () -> Unit = {},
content: @Composable () -> Unit = {}
) {
Scaffold(
modifier = Modifier,
bottomBar = { bottomBar() },
floatingActionButton = {
FloatingActionButton(
containerColor = appColors.primary,
shape = CircleShape,
onClick = {},
modifier = Modifier,
) {
Icon(Icons.Filled.Add, null,tint = Color.White)
}
}
) { safePadding ->
Box(
modifier = Modifier.padding(
bottom = safePadding.calculateBottomPadding()
)
) {
content()
}
}
}
可以使用如下代碼記錄不同頁面的router
:
var recordRouter by remember { mutableStateOf("") }
切換到不同的頁面並更新recordRouter
值。
當FloatingActionButton
被點擊時,判斷recordRouter屬於哪個頁面,然后觸發相應的事件方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.