Activity.xml
<EditText
android:id="@+id/et_pwd"
android:layout_width="300dp"
android:layout_height="37dp"
android:layout_marginBottom="15dp"
android:drawableLeft="@drawable/icon_password"
android:hint="Password"
android:inputType="textPassword"
android:maxLength="20"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" />
Button OnClickListner
if (et_password.getInputType() != (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)) {
et_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
et_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
First of all, I set digits on the EditText, and if I click a button it implements the above code which changes its inputType. Before I change the inputType, its digits are working. However, after changing its inputType its digits are not working for some reasons. It allows special characters to be entered. How can I improve my code to make it work?