Is there any way to set the width of an EditText i...
# compose
d
Is there any way to set the width of an EditText in characters?
h
Wouldn't just trimming the string work?
Copy code
Text(
  text = myString.take(limit)
)
d
Sorry, by text field I meant EditText
h
oh sorry, my mistake 🤦‍♂️ Again similarly you have the ability to ignore anything longer than what you want
Copy code
var text by remember { mutableStateOf("") }
TextField(
  value = text,
  onValueChange = {
    text = it.take(limit)
  }
)
🙌 1
argument names might be wrong, haven't used TextField in a while
d
Yeah, but I want to set the visible width such that it wraps the amount of text in the EditText. As in if
value = "0.000"
I don't want a bunch of whitespace on the right, I want it to end after the last 0
h
Hmm, that's an interesting challenge. Your best bet might be
onTextLayout
and figuring out how much space your TextField should allocate.
This might cause you to lose a frame tho
d
Thanks for the suggestion. It's good to know there's no great solution. If it's numbers with sane fonts I think I can rely on the fact 1em is slightly larger than the width of a zero, so that might work