Android中设定EditText的输入长度

如何限定Android的Text中的输入长度呢?
方法一:可以在layout xml中加上属性android:maxLength
比如:
<EditText
        android:id="@+id/editTextShow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hint"
        android:cursorVisible="false"
        android:lines="1"
        android:maxLength="16"
        />
 
方法二:在代码中控制
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
posted on 2012-09-22 20:57  Fra~~kaka  阅读(43355)  评论(0编辑  收藏  举报