🙄

Jetpack Composeでタブレイアウトを作る

2022/08/09に公開

タブはこれだけでした

@Composable
fun TabLayout() {
    var selectedTabIndex by remember { mutableStateOf(0) }

    TabRow(
        selectedTabIndex = selectedTabIndex,
        backgroundColor = MaterialTheme.colors.surface,
    ) {
        Tab(
            selected = selectedTabIndex == 0,
            onClick = {
                selectedTabIndex = 0
            },
            text = {
                Text(
                    text = "タブ1",
                    fontWeight = FontWeight.Bold,
                    color = if (selectedTabIndex == 0) FaansTheme.colors.MONO_B13 else FaansTheme.colors.MONO_B60
                )
            }
        )
        Tab(
            selected = selectedTabIndex == 1,
            onClick = {
                selectedTabIndex = 1
            },
            text = {
                Text(
                    text = "タブ2",
                    fontWeight = FontWeight.Bold,
                    color = if (selectedTabIndex == 1) FaansTheme.colors.MONO_B13 else FaansTheme.colors.MONO_B60
                )
            }
        )
    }
}

Discussion