Ok everyone knows that to hide a keyboard you need to implement:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hi
This one is the easiest solution for me (and worked out by me).
This is the method to hide the keyboard.
public void hideKeyboard(View view){
if(!(view instanceof EditText)){
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),0);
}
}
now set onclick attribute of the parent layout of the activity to above method hideKeyboard
either from the Design view of your XML file or writing below code in Text view of your XML file.
android:onClick="hideKeyboard"