TextView设置MaxLength

问题

如何设置TextView的最大长度?xml和java方式都需要

答案

1 . xml方式

<TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxLength="12"/>

2 . Java方式

textView.setFilters(new InputFilter[] { new InputFilter.LengthFilter(12) });

参考1:How to programmatically set maxLength in Android TextView?

参考2:How to Get EditText maxLength setting in code

你可能感兴趣的:(android,textview)