Reputation: 10078
There's a way to set height of an EditText for contains at least n character ?
Upvotes: 0
Views: 194
Reputation: 5961
There are some number of ways that you can limit the editText as number of characters within multiple line as well.
Firstly, set this in your .xml:
android:inputType="textMultiline"
android:maxLength="n"
Secondly, you can also use a way around to reach your goal. Here it is. Implement TextWatcher to let user enter just 'n' characters. Whenever user enters 'n' characters, set the EditText to non-editable. And also set OnFocusChangeListener to it.
EditText editText = (EditText)findViewById(R.id.entry);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
For more details and also explanation of textWatcher, you can have a look number of input characters.
For more manipulation on multiple lines. You can set the number of lines this way, after you have set textMultiline, you can use any or some of below:
android:lines="8"
android:minLines="6"
android:maxLines="10"
android:scrollbars="vertical/horizontal"
Upvotes: 1
Reputation: 25028
Use android:layout_height="wrap_content"
in your EditText
.
If you want a single row of text only, use android:singleLine="true"
If you want it to have a minimum height set, use android:minHeight="x dp"
If you want it to be exactly n
lines tall, use android:lines
Upvotes: 0