Android JetPack组成:浏览文本字段

发布于 2025-02-01 17:08:15 字数 599 浏览 4 评论 0原文

我实现了一个具有很多文本场的屏幕,并将脚手架用作根层。 因为我希望我的屏幕是RTL,所以我使用了构图本地提供商()。

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl ) {}

我的文本场在屏幕上像这样:

BA

DC

,当我想浏览这些Textfields时:

keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(
      onNext = { LocalFocusManager.current.moveFocus(FocusDirection.Next) }
)

我希望发生的事情:a - > b - > c - > D

发生了什么:b - > a - > D - > c

(我为父词使用了一个列,但文本字段的行作为父根二乘两个(排在列中))

有人可以帮忙吗? 谢谢。

I implemented a screen that has a lot of TextFields and I used the scaffold as a root layer.
Because I wanted my screen to be rtl, I used Composition Local provider().

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl ) {}

My TextFields were on the screen like this:

B A

D C

and when I wanted to navigate through these TextFields:

keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(
      onNext = { LocalFocusManager.current.moveFocus(FocusDirection.Next) }
)

what I Expected to happend: A -> B -> C -> D

what happend: B -> A -> D -> C

(I used a Column for parent root but textfields have Row as Parent root two by two (the Rows are in Column))

Can anyone help?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

圈圈圆圆圈圈 2025-02-08 17:08:15

您可以使用.focusorder修饰符来实现这一目标:

Column() {
    val (aFocus, bFocus, cFocus, dFocus) = remember { FocusRequester.createRefs() }


    Row {
        OutlinedTextField(
            value = "A",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(aFocus) { next = bFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
        )
        OutlinedTextField(
            value = "B",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(bFocus) { next = cFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
    }

    Row {
        OutlinedTextField(
            value = "C",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(cFocus) { next = dFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
        OutlinedTextField(
            value = "D",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(dFocus) { },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
    }
}

You can use .focusOrder modifier to achieve this:

Column() {
    val (aFocus, bFocus, cFocus, dFocus) = remember { FocusRequester.createRefs() }


    Row {
        OutlinedTextField(
            value = "A",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(aFocus) { next = bFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
        )
        OutlinedTextField(
            value = "B",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(bFocus) { next = cFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
    }

    Row {
        OutlinedTextField(
            value = "C",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(cFocus) { next = dFocus },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
        OutlinedTextField(
            value = "D",
            onValueChange = {},
            modifier = Modifier
                .weight(1f)
                .focusOrder(dFocus) { },
            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
        )
    }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文