Last active
November 20, 2021 06:43
-
-
Save TheMelody/5681affaf39600b1f974f4db214a7b0a to your computer and use it in GitHub Desktop.
Jetpack Compose - FloatingActionButton 展开/折叠 的多级悬浮菜单
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) 2021 fuqiang | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//屏幕右下角显示Fab按钮 | |
Box(modifier = Modifier.padding(bottom = 25.dp) | |
.fillMaxSize().wrapContentSize(align = Alignment.BottomEnd)){ | |
TestMultiFab() | |
} | |
/** | |
* 测试代码 | |
**/ | |
@Composable | |
fun TestMultiFab(){ | |
val expandFbItemList: MutableList<MultiFabItem> = mutableListOf( | |
MultiFabItem( | |
srcIconColor = Color.White, | |
fabBackgroundColor = Color.Black, | |
labelBackgroundColor = Color.Red.copy(alpha = 0.45F), | |
labelTextColor = Color.Blue.copy(alpha = 0.45F), | |
//自己设置一个图片或者svg | |
icon = ImageVector.vectorResource(id = R.drawable.ic_edit_file), | |
label = "创建文件" | |
), | |
MultiFabItem( | |
srcIconColor = Color.Yellow, | |
fabBackgroundColor = Color.DarkGray, | |
//自己设置一个图片或者svg | |
icon = ImageVector.vectorResource(id = R.drawable.ic_import_file), | |
label = "导入文件" | |
) | |
) | |
val context = LocalContext.current | |
MultiFloatingActionButton(srcIcon = Icons.Filled.Add, showLabels = true,items = expandFbItemList) { | |
//弹出来的item被点击了 | |
Toast.makeText(context.applicationContext,"点击了:${it.label}",Toast.LENGTH_SHORT).show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the example. There will be a problem if you add this to a scaffold and have
labels = true
andisFloatingActionButtonDocked = true
. Maybe you want to update with a bug fix for that. :)