V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhwguest
V2EX  ›  Android

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

  •  
  •   zhwguest · 2023-04-25 18:51:05 +08:00 · 4119 次点击
    这是一个创建于 366 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    8 条回复    2023-04-29 17:44:35 +08:00
    ho121
        1
    ho121  
       2023-04-25 19:19:45 +08:00 via Android
    换个思路,不如造个这样的轮子,说不定会火
    maokg
        2
    maokg  
       2023-04-25 19:38:17 +08:00
    看成了 sharedpreference
    Mystery0
        3
    Mystery0  
       2023-04-25 19:57:12 +08:00
    jinyang656
        4
    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
        5
    winterbells  
       2023-04-25 20:42:59 +08:00 via Android
    现在都是让 chatgpt 直接给了 :doge
    yor1g
        6
    yor1g  
       2023-04-25 21:36:02 +08:00
    不就是几个 Card 加个点击事件 ...
    zhwguest
        7
    zhwguest  
    OP
       2023-04-25 22:00:47 +08:00
    谢谢各位。其实自己来 compose 不是不可以,但是做控件的都知道,里面有很多小细节,不一定跟 native 的控件一致。另外就是有点想不通为什么不提供。
    既然没有那就慢慢造吧。
    fromzero
        8
    fromzero  
       362 天前
    compose 默认只提供了 material design 的控件 ,https://m3.material.io/components 因为 SwitchPreference 不在 material design 的设计规范里
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:12 · PVG 20:12 · LAX 05:12 · JFK 08:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.