Android开发之EditText输入框限制输入数字和字母的实现方式

老套路先看效果图:

非常简单只需要在xml不居中添加一个属性就可以了:

android:digits="0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"

完整如下:

 <EditText
        android:id="@+id/etLoginPwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="15dp"
        android:layout_toRightOf="@+id/tvLoginPwd"
        android:background="@null"
        android:digits="0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"
        android:hint="请输入密码"
        android:maxLength="20"
        android:textColor="#999999"
        android:textSize="12sp" />

当然也可以直接使用android:inputType="textPassword"这个属性也可以达到相同的效果

猜你喜欢

转载自blog.csdn.net/xiayiye5/article/details/109687465