Search code examples
androidandroid-edittext

How to set an EditText's initial height while allowing it to expand when overflows


I am currently working on an android app and i'm having some problems with EditText.

I want to create an editText with an empty string starting off with the height equivalent to 1 or more lines and maintaining that height, but allowing it to grow when text starts to overflow beneath the current size.

I tried several things :

  1. If I set the Edittext's size to a certain value, it doesn't grow... the previous lines just go up and become invisible

  2. When I don't set the size and use the default height, then the edittext always starts off with the height of two lines, not 1 line.

How can I fix this?


Solution

  • you can try to use wrap content which should expand with the text

    <EditText 
    android:width = "match_parent"
    android:height= "wrap_content"/>