简体   繁体   中英

EditText Character Limit for Hint

I set a limit for the EditText as 1;

InputFilter[] editFilters = editText.getFilters();
InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
newFilters[editFilters.length] = new InputFilter.LengthFilter(1); //the desired length
editText.setFilters(newFilters);

But I want to write something that has 2 characters length for HintText. But I cannot do it because of the character limit.

What I mean is, When I want to write something limit must be 1, but for the hint it must be 2.

Is there a way to make it?

Use android:maxLength="1" in layout XML can solve your problem.

It will limit the input length to 1 and doesn't affect the hint length.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM