3

I have an EdiText in my project developed on android studio .

android:id="@+id/Number"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:textSize="24dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"

I need to find a way to disable the keyboard when I click on the edit text, meaning that when I click on the EditText the keyboard should not open .

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
  • 1
    Possible duplicate of [How to disable keypad popup when on edittext?](https://stackoverflow.com/questions/10611833/how-to-disable-keypad-popup-when-on-edittext) – Vince Dec 27 '17 at 16:48

5 Answers5

4

Just disable it.

EditText et = (EditText) findViewById(R.id.edittext);
et.setEnabled(false);

OR

Add android:inputType="none" in your xml

mrid
  • 5,782
  • 5
  • 28
  • 71
2

In your code you need to do it programmatically this way: declare a global variable for InputMethodManager:

 private InputMethodManager im ;

In onCreate() method define it:

im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(youredittext.getWindowToken(), 0);

Set the onClickListener to that edit text inside onCreate():

youredittext.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        im.showSoftInput(youredittext, InputMethodManager.SHOW_IMPLICIT);
    }
});

This will work.

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Nawrez
  • 3,314
  • 8
  • 28
  • 42
2

Do it this way

final EditText editText = findViewById(R.id.Number);
        editText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
            }
        });
LeoNeo
  • 739
  • 1
  • 9
  • 28
2

here you go.

public static void disableSoftInputFromAppearing(EditText editText) {
    if (Build.VERSION.SDK_INT >= 11) {
        editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
        editText.setTextIsSelectable(true);
    } else {
        editText.setRawInputType(InputType.TYPE_NULL);
        editText.setFocusable(true);
    }
}
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
0

If you want to prevent user to edit text then you may use android:enabled="false" property in edittext

Munir
  • 2,548
  • 1
  • 11
  • 20