Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Android keyboard from reverting back to alphabetic mode

I have an App which requires the input of a sequence of space-separated hex digit groups (much like a product key) into an EditText, such as AB34 67EF ...

The problem is that every time a numeric digit is entered followed by space, the Android keyboard automatically switches back to alphabetic mode, which is both confusing and highly annoying to the user.

For example, when typing the two groups above, the keyboard will remain in numerics mode when '3' is pressed, but then switches to letters mode when the space key is hit after '4' - meaning the user then has to manually switch back to numerics before entering '6'.

The EditText control (below) has textNoSuggestions flag set for the input type, but no matter what inputType and what keyboard settings I change, I cannot get the keyboard to stay in numerics mode following a space.

   <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:inputType="textCapCharacters|textNoSuggestions"
        android:ems="10" >

        <requestFocus />
    </EditText>

Is there any way to force the keyboard to stay in the current mode after a space character is entered or, alternatively, a way to programatically switch the keyboard mode?

like image 352
adelphus Avatar asked Nov 13 '13 13:11

adelphus


People also ask

What is inputType in android?

The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.


1 Answers

I needed the same. The inputType textVisiblePassword did the trick for me. Reference: InputType

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:inputType="textVisiblePassword|textCapCharacters"
    android:ems="10" >

    <requestFocus />
</EditText>
like image 116
D.Kastier Avatar answered Oct 19 '22 10:10

D.Kastier