EditText with number keypad by default, but allowing alphabetic characters

Frank Bozzo picture Frank Bozzo · Aug 23, 2010 · Viewed 60.8k times · Source

I have an EditText box and I want the default keyboard that comes up when it is selected to be the numeric keypad, since most of the time users will be entering numbers. However, I do want to allow users to enter alphabetic characters too, if they need to. Using android:inputType="number" restricts input to numeric digits only. What options do I have?

Answer

Diego Santamaria picture Diego Santamaria · Sep 2, 2016

Define your EditText in your xml this way:

<EditText 
    android:id="@+id/txtOppCodigoCliente"
    android:inputType="textVisiblePassword"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:maxLength="11"
    android:hint="@string/strCodigoCliente"/>

output: android:inputType="textVisiblePassword"

A row of numbers and the rest of letters.