Android Hide Keyboard Not Working - Cannot Hide Soft Keyboard


Answer :

Changing HIDE_IMPLICIT_ONLY to 0 did it (after I changed tohideSoftInputFromWindow() from of hideSoftInputFromInputMethod()).

However I'm not sure why HIDE_IMPLICIT_ONLY isn't working since I am not explicitly opening the keyboard with a long press on Menu.


Another option to prevent it from activity in AndroidManifest.xml file

android:windowSoftInputMode="stateAlwaysHidden" - This method will prevent loading/showing keyboard when the activity is loaded. But when you click the editable component like edittext the keyboard will open. perfect for my requirement.

<activity             android:name=".Name"             android:label="@string/app_name"              android:windowSoftInputMode="stateAlwaysHidden"> 

1.first bind your edit text token with keyboard and open
i.e inputMethodManager.showSoftInput(_edittext, 0); //here _edittext is instance of view

2.keyboard will get hidden automatically if the edit text goes hidden from the screen

3.edit text is still on screen but you want to hide the keyboard then use below code imm.hideSoftInputFromWindow(_edittext.getWindowToken(), 0); //this won't work if edittext is not on screen or not focused.


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable