Android中EditText中的InputType
在工作过程中遇到了EditText的输入类型,从而使用到了InputType。
最为常见的是在XML文件的EditText标签下定义
<EditText android:id="@+id/etTest"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
也可以在代码中设置InputType
editText.setInputType(InputType.TYPE_CLASS_PHONE);//只能输入电话号码
editText.setInputType(InputType.TYPE_CLASS_NUMBER);//只能输入数字
editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);//只能输入邮箱地址
editText.setInputType(InputType.TYPE_NULL); // 禁止输入(不弹出输入法)
...