0

I am developing an android app where most users use a hardware keyboard attached to the android device for easy character input.

Even though the hardware keyboard is present, when user clicks on an EditText, the virtual keyboard pops up which is unnecessary.

I need to give the user a setting to completely disable the virtual keyboard so they can use the hardware keyboard alone.

This question has several answers on how to disable soft keyboard for a single EditText, but conditionally disabling soft input for inividual EditTexts is quite difficult for me since there are large number of activities which contain EditTexts.

One way to do is to install Null Keyboard app and select it as the virtual keyboard from android settings as described here, but I don't want users of my application to rely on a third party application.

Is there a way to globally disable virtual keyboard without disabling it for individual screens?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • 1
    Possible duplicate of [How to hide Android soft keyboard on EditText](https://stackoverflow.com/questions/8997225/how-to-hide-android-soft-keyboard-on-edittext) – RonTLV Jul 07 '19 at 05:44
  • @RonTLV the answers in that question are focused on how to disable soft keyboard for a single `EditText` element. What I am looking for is a way to conditionally disable soft input in all `EditText` elements from a single place without changing code in each place I have used an `EditText` in the application. – Lahiru Chandima Jul 07 '19 at 08:10

1 Answers1

0

If you want to disable keyboard for all EditTexts You can create a custom EditText and disable keyboard functionality in it. And in your Project use your own custom NoKeyboardEditText instead of using Native EditText. Like

public class NoKeyboardEditText extends EditText {


    public NoKeyboardEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }


    public void init() {
        setInputType(InputType.TYPE_NULL);
    }

}

Now in your XML, your can use your Custom NoKeyboardEditText in this way

<com.your_package_name.NoKeyboardEditText
 ... // add all other attributes here
/>

Or

I found another solution here, have a look on it, if it solves your problem.

Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36