Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a hint wrap in an Android EditText?

My EditText hint is not wrapping. A hint isn't very useful if the last part is cut off. I am very cautious about restricting/forcing the dimensions my EditText box to ensure it looks decent regardless of screen dimensions.

Here's what the relevant XML looks like:

    <EditText android:id="@+id/ET1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="left"
        android:hint="@string/Hint1" 
        android:lines="3">
    </EditText>

I've already set android:lines="3" to mitigate the issue, but it isn't enough. In order to maximize compatibility with various screen dimensions I would prefer OS wrapping over me putting in line breaks and hard returns in the string. There are other things happening in the view which also compel me to not manually set the width of the box to promote good breaks.

like image 496
Will Avatar asked Mar 01 '09 05:03

Will


2 Answers

Perhaps you were using an old version of the SDK?

I've verified that the following hint wraps to 3 lines without any problem in Android 1.5 cupcake:

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18px"
        android:gravity="left"
        android:hint="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse egestas ullamcorper facilisis." />
like image 169
emmby Avatar answered Nov 09 '22 21:11

emmby


Add this to the EditText

android:inputType="textMultiLine"
like image 3
Faraaz Avatar answered Nov 09 '22 20:11

Faraaz