lurenjiauser
V2EX  ›  Android

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

  •  
  •   lurenjiauser · Apr 25, 2023 · 13415 views
    This topic created in 1293 days ago, the information mentioned may be changed or developed.

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

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

    8 replies  •  2023-04-29 17:44:35 +08:00
    ho121
    ho121
    Apr 25, 2023 via Android
    1
    换个思路,不如造个这样的轮子,说不定会火
    Yasuke
    Yasuke
    Apr 25, 2023
    2
    看成了 sharedpreference
    yufz
    yufz
    Apr 25, 2023
    4
    ```
    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
    300
    300
    Apr 25, 2023 via Android
    5
    现在都是让 chatgpt 直接给了 :doge
    yor1g
    yor1g
    Apr 25, 2023
    6
    不就是几个 Card 加个点击事件 ...
    lurenjiauser
    lurenjiauser
    OP
    Apr 25, 2023
    7
    谢谢各位。其实自己来 compose 不是不可以,但是做控件的都知道,里面有很多小细节,不一定跟 native 的控件一致。另外就是有点想不通为什么不提供。
    既然没有那就慢慢造吧。
    fromzero
    fromzero
    Apr 29, 2023
    8
    compose 默认只提供了 material design 的控件 ,https://m3.material.io/components 因为 SwitchPreference 不在 material design 的设计规范里
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4406 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 03:27 · PVG 11:27 · LAX 19:27 · JFK 22:27
    ♥ Do have faith in what you're doing.