https://kotlinlang.org logo
#compose
Title
# compose
g

galex

07/06/2022, 2:02 PM
How can I align a
Text
to the start of the
Text
as label in a
TextField
?
Copy code
@Composable
fun SomeTextField(
    label: String,
) {

    TextField(
        label = {
            Text( // text label here
                text = label
            )
        }
    )

    Text("Here is an error text") // align this to start where the text label starts
}
🤔
l

Luke

07/06/2022, 2:50 PM
I'm really not sure it would work but with a ConstraintLayout maybe? I'm not sure you can add constraints to composables not directly in the layout (like label here) but it's worth investigating
g

galex

07/06/2022, 2:51 PM
Right, I'll try!
c

Colton Idle

07/06/2022, 4:01 PM
When I'm back at my desk I can check how I did this from the samples.
🙏 1
I think I copied my implementation based on one of these samples here. You can pretty much copy pasta this entire thing into your project and play around with all of the text field samples: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]samples/TextFieldSamples.kt?q=compose%20sample%20text%20field
c

Chris Sinco [G]

07/06/2022, 10:29 PM
The padding of TextField is specific to the Material Design spec, so aligning perfectly will have to be done through manually nudging Text
💯 1
g

galex

07/07/2022, 7:33 AM
Yeah that's what I thought, thanks to you two @Colton Idle @Chris Sinco [G] 💙
👍 1
3 Views