Search code examples
androidandroid-edittextandroid-linearlayout

EditText textmultiline to display 3 lines by default


Android Studio 0.4.4

Hello,

I would like the EditText property textmultiline to display 3 lines by default. However, I can't seen to do that. As it always displays 1 line. Is there any way I can do this using the LinearLayout?

Here is my xml file:

<TextView
    android:id="@+id/tvName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvPhone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<TextView
    android:id="@+id/tvEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"/>

<EditText
    android:id="@+id/etMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22sp"
    android:hint="Enter your message"
    android:inputType="textImeMultiLine"
    android:minLines="3"
    android:gravity="top|left">

    <requestFocus/>
</EditText>

<Button
    android:id="@+id/btnSendMessage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Send Message"
    android:textSize="22sp"/>

<ImageView
    android:id="@+id/ivEmailPicture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="Picture of email being send"
    android:src="@drawable/email"/>

And a screen shot of my current design, as you can see the editText (Enter your message) is only displaying 1 line.

Many thanks for any suggestions,

enter image description here


Solution

  • Add this to your EditText's xml code.

    android:lines="3" 
    

    I'm not sure if it will solve your problem but refering to the documentation it should.