【问题标题】:Using the ScrollableTabRow I create the tabs But I want to know how to navigate to each page使用 ScrollableTabRow 我创建选项卡但我想知道如何导航到每个页面
【发布时间】:2021-05-01 01:11:53
【问题描述】:

使用抽屉内容,我在功能之间导航 使用 ScrollableTabRow 我创建了标签但我想知道如何导航到每个页面......

我的代码:

@Composable
fun ScrollableTabRowDemo() {
    val state = remember { mutableStateOf(0) }
    val titles = listOf("1", "2", "3", "4", "5")
    Column {
        ScrollableTabRow(
                selectedTabIndex = state.value,
                modifier = Modifier.wrapContentWidth(),
                edgePadding = 16.dp
        ) {
            titles.forEachIndexed { index, title ->
                Tab(
                        text = { Text(title) },
                        selected = state.value == index,
                        onClick = { state.value = index }
                )
            }
        }

        Spacer(modifier = Modifier.height(20.dp))

        Text(
                modifier = Modifier.align(Alignment.CenterHorizontally),
                text = "${state.value + 1}",
                style = MaterialTheme.typography.body1
        )
    }
}

【问题讨论】:

  • 导航到每个页面是什么意思?使用您的代码,您可以通过选择所需的选项卡进行导航

标签: android android-jetpack-compose


【解决方案1】:

成功了

@Composable
fun ScrollableTabRowDemo() {
    val state = remember { mutableStateOf(0) }
    val titles = listOf("Home", "Cadastro")

    Column {
        ViewPagerScreen()

        ScrollableTabRow(
                selectedTabIndex = state.value,
                backgroundColor= colorResource(id = R.color.green),
            modifier = Modifier
            .wrapContentWidth()
                ,indicator = { tabPositions ->
            TabRowDefaults.Indicator(
                    color = Color.Red,
                    height = 4.dp,
                    modifier = Modifier
                        .tabIndicatorOffset(tabPositions[state.value])
            )

        }

        ) {
            titles.forEachIndexed { index, title ->
                Tab(
                        text = { Text(title,color = Color.White) },
                        selected = state.value == index,
                        onClick = { state.value = index },
                        modifier = Modifier.align(Alignment.CenterHorizontally)


                )
            }
        }

        Spacer(modifier = Modifier.height(20.dp))

        Column() {
            if(state.value==0){
                RecyclerView()
            }else{
                Form()
            }
        }

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多