Search code examples
androidandroid-edittextnumbersandroid-softkeyboardandroid-textinputedittext

How to remove special characters from ANDROID KEYBOARD without using custom keyboard?


I want user to input only numbers in my edit text in android application.For that I have added android:inputType="number" property in edit text.

But now, for some reason, I need to remove special characters from ANDROID KEYBOARD itself. I know that using custom keyboard, I might be able to do that, but is there any other way by which I can achieve this if I don't want to create a custom keyboard?

   <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/edt_salary"
                    android:layout_width="match_parent"
                    android:inputType="number" 
                    android:layout_height="wrap_content"/>

Solution

  • I need to remove special characters from ANDROID KEYBOARD itself

    There are over 20,000 Android device models, from a variety of manufacturers. There are hundreds of pre-installed input method editors (soft keyboards) across those device models. There are hundreds of other ones that users can install from the Play Store and other app distribution channels. There is no single "ANDROID KEYBOARD".

    is there any other way by which I can [remove special characters] if I don't want to create a custom keyboard?

    No. Even android:inputType is a hint. It is up to the developers of the input method editor to decide what the UI of the input method editor will be. Some have no keys at all (e.g., Grafiti keyboard that uses gestures).

    I know that using custom keyboard, I might be able to do that

    Please take accessibility into account and ensure that all of your users will be able to use any such custom keyboard.