How can I create a multiline edittext with text limit? I set the maxLength of edittext but it made the edittext singleline and if I add inputType to textMultiLine then the imeOptions set as actionDone won't show. I don't want to set static value for the maxLines attribute.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activityNameHint"
android:inputType="textMultiLine"
android:maxLength="500"
android:imeOptions="actionDone"
/>
And also when the edittext reaches its limit the keyboard is still allowing the text which makes it difficult to delete the text. How to solve this issue?
new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
}
});
by overriding text change listener, you can specify the max length in ontextchange() and add condition there and do what ever you want
You can try this code:
android:maxLines="3"
android:minLines="3"
android:gravity="left"
android:maxLength="500"
android:inputType="textMultiLine"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.