Search code examples
androidkotlinandroid-edittext

Hide the keyboard after clicking on the EditText


I'm using Date and Time Picker to handle the meeting date field, so there is no need for the keyboard. How can I prevent the keyboard from showing after clicking on the field?enter image description here


Solution

  • You can use property android:focusableInTouchMode="false" in xml

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:inputType="text|date"/>
    

    And add click listener to this view in code

    editText.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
           //show date picker
        }
    });