In this video it shows the code to hide the soft input method (key-board defined in Android OS) when any of the input widget, such as Edit Text (Plain Text) is clicked in the Android App.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.keyboarddiableedittext;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText editText;
private InputMethodManager inputMethodManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
editText.setFocusable(false);
inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
}
public void editTextClickMethod(View view){
// Both will work:
// inputMethodManager.hideSoftInputFromWindow(view.getRootView().getWindowToken(), 0);
inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(),0);
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="234dp"
android:layout_height="103dp"
android:layout_marginStart="88dp"
android:layout_marginTop="60dp"
android:ems="10"
android:inputType="text"
android:onClick="editTextClickMethod"
android:text="Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>