DEV Community

Cover image for Resize TextField in Jetpack Compose
Raksha for Canopas Software

Posted on

1

Resize TextField in Jetpack Compose

Do you know how to make TextField responsive to fit content perfectly?

Let’s make TextField Responsive to fit perfectly within its bounds.

I was working on the app where I needed a few TextField that should resize as the text grows. Currently, there’s no way to accomplish this in Jetpack compose. So let’s implement a custom resizable text field.

We’ll implement the TextField that resizes depending on the fixed height.

The complete source code of the implementation is available on GitHub.

I've divided the implementation into smaller parts to make it easy.

  1. Calculate the line count and height of the Text with the given Text Style
  2. Shrink the font size to fit on the specified max line

For detailed implementation, check out our blog.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay