http://dotinstall.com/lessons/browser_android_v2/32604
I wrote the code as per the above site, but when I see it in the emulator, the keyboard appears by default, and it doesn't disappear even if I unfocus the edit text.
How do I hide my keyboard?
To hide the soft keyboard, you must write the code you want to hide when the user hides the or app is out of focus (for example).
For example, a listener who hides the keyboard when the focus is off will write:
View.OnFocusChangeListener focusLostSoftKeyboardHide=newView.OnFocusChangeListener(){
@ Override
public void onFocusChange (View view, boolean hasFocus) {
if(!hasFocus){
InputMethodManager imm=(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
};
© 2024 OneMinuteCode. All rights reserved.