我们知道,
maxLength
对于EditText
的设置是:
android:maxLength="19"
或以编程方式。我的问题是,如果它被设置为特定长度,我如何以编程方式删除它?我想将
maxLength
设置为可能的最大长度。maxLength
etEmail.filters = arrayOf<InputFilter>()
EditText et = new EditText(this);
int maxLength = 3;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
et.setFilters(FilterArray);
文件中并使用它:-)
ext
fun styleLimitText(text: String, length: Int): String {
if (text.length > length) return text.substring(0, length) + "..."
return text
}
或以编程方式
android:maxLength="-1"