Reputation: 329
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 :
If I set the Edittext's size to a certain value, it doesn't grow... the previous lines just go up and become invisible
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?
Upvotes: 4
Views: 4568
Reputation: 11
Anyone else still having issue with this or with TextInputEditText in the material design? It seems like the internal padding for TextInputEditText is automatically adjusted even when setting explicit android:textSize android:minLines and android:minHeight. You still have to explicitly set the padding.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:inputType="textMultiLine"
android:minLines="1"
android:minHeight="35dp"
android:paddingHorizontal="16dp"
android:paddingVertical="0dp"/>
<!-- /\ Add the two lines above /\ -->
</com.google.android.material.textfield.TextInputLayout>
Upvotes: 0
Reputation: 1048
How about using these option?
android:maxHeight="100dip"
android:minHeight="40dip"
MaxHeight will force your EditText's height no more than 100dip.
MinHeight will force your EditText's height minimum is 40dip.
Example)
<EditText
android:id="@+id/somethingEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="56dip"
android:maxHeight="200dip"
android:minLines="1" />
This code will force your EditTex's height range to '56dip ~ 200dip'
Upvotes: 7
Reputation: 1463
You can set minimum lines using minLines Property of edittext, also use height as wrap content to make it expandable.
<EditText
android:width = "match_parent"
android:height= "wrap_content"
android:minLines="1"/>
Upvotes: 5
Reputation: 13435
you can try to use wrap content which should expand with the text
<EditText
android:width = "match_parent"
android:height= "wrap_content"/>
Upvotes: 1