简体   繁体   English

Jetpack Compose 中的自定义 TabRow

[英]Custom TabRow in Jetpack Compose

I use TabRow and I have two questions:我使用 TabRow,我有两个问题:

  • Is it possible to remove a line that is wide the entire width screen?是否可以删除整个屏幕宽度的线?

  • How Can I bring the buttons together (reduce space between them)我如何将按钮放在一起(减少它们之间的空间)

在此处输入图片说明

To remove the line under the tabs just set an empty divider by passing divider = {} .要删除选项卡下的行,只需通过传递divider = {}设置一个空分隔divider = {}

To make the tabs fill the space available in the TabRow (therefore without empty spaces), just do not set a specific size to the Tabs, the following example works as you ask.要使选项卡填充TabRow可用空间(因此没有空格),只需不要为选项卡设置特定大小,以下示例按您的要求工作。

var state by remember { mutableStateOf(0) }
val titles = listOf("TAB 1", "TAB 2")
Column {
    TabRow(selectedTabIndex = state, divider = {}) {
        titles.forEachIndexed { index, title ->
            Tab(
                text = { Text(title) },
                selected = state == index,
                onClick = { state = index }
            )
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM