James_Duh James_Duh - 1 month ago 7
Android Question

Android Studio 2.2 inputType not working

I have upgraded to Android Studio 2.2 from 2.1 now when I set the inputType to text on a EditText widget it will not restrict my entry to text only. This is happening on new projects. My older projects the concept works fine. Android Studio 2.2 is asking me to update to Gradle plugin V 2.2.1 and Version 2.14.1 on older projects. Is this a BUG or am I setting something wrong in my XML file?
I thought this issue would be fixed with AS 2.2.1 build 145-3330264 but no change. I have searched SO and tried various fixes related to junit 4.12 jar that is not present in new projects with no results.

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:text="Name"
android:id="@+id/etPW"
android:layout_marginTop="50dp"
android:layout_marginLeft="140dp"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="16sp"
android:inputType="text"
android:gravity="bottom"/>

Answer

You can add this to your XML:

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

That should not allow numbers to be entered (or punctuation, so add whatever characters you want to allow). I tested it and it worked for me.

Comments