在 jetpack Compose 中可以不用自己造类似 SwitchPreference 这样的轮子么?

2023-04-25 18:51:05 +08:00
 zhwguest

比如我有一个 composable 的一个组件,其中更要包含几个类似 SwitchPreference 、TextPreference 这样的控件。

难道非得自己一个个从 Text\Icon 去 Compose 么?没有已经造好的轮子么?

4308 次点击
所在节点    Android
8 条回复
ho121
2023-04-25 19:19:45 +08:00
换个思路,不如造个这样的轮子,说不定会火
maokg
2023-04-25 19:38:17 +08:00
看成了 sharedpreference
Mystery0
2023-04-25 19:57:12 +08:00
jinyang656
2023-04-25 20:39:58 +08:00
```
ListItem(
headlineText = { Text("Hello") },
supportingText = { Text("Hello World") },
leadingContent = { Icon(imageVector = Icons.Filled.Settings, contentDescription = "") },
trailingContent = { Switch(checked = true, onCheckedChange = {}) }
)
```
如果只是要个简单的 UI ,可以试下 androidx.compose.material3 下的 ListItem
winterbells
2023-04-25 20:42:59 +08:00
现在都是让 chatgpt 直接给了 :doge
yor1g
2023-04-25 21:36:02 +08:00
不就是几个 Card 加个点击事件 ...
zhwguest
2023-04-25 22:00:47 +08:00
谢谢各位。其实自己来 compose 不是不可以,但是做控件的都知道,里面有很多小细节,不一定跟 native 的控件一致。另外就是有点想不通为什么不提供。
既然没有那就慢慢造吧。
fromzero
2023-04-29 17:44:35 +08:00
compose 默认只提供了 material design 的控件 ,https://m3.material.io/components 因为 SwitchPreference 不在 material design 的设计规范里

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/935445

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX