I have coded below general, everytime usable functions to display and dismiss keyboard:
|==| Display and Dismiss keyboard Programmatically:
InputMethodManager iptKeybodMgrVar; void keybodDspFnc(EditText txtEdtVyuVar) { txtEdtVyuVar.requestFocus(); if (iptKeybodMgrVar == null) { iptKeybodMgrVar = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); } iptKeybodMgrVar.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } void keybodDsmFnc(EditText txtEdtVyuVar) { iptKeybodMgrVar.hideSoftInputFromWindow(txtEdtVyuVar.getWindowToken(), 0); } But problem is, When the Edit Text is below Keyboard, The activity does not shift upwards. It shifts only when a user starts typing.
So how do I make it shift upwards as soon as keyboard appears?
I went thru all links below and nothing helped me:
Android: How do I prevent the soft keyboard from pushing my view up?
adjustPan not preventing keyboard from covering EditText
Android : Soft Keyboard covering edit text up (adjustresize or adjustpan doesnt work)
I tried and didn't work:
android:windowSoftInputMode="adjustPan|stateAlwaysHidden" android:windowSoftInputMode="adjustResize|stateAlwaysHidden" android:windowSoftInputMode="adjustResize|adjustPan" Also tried this codes:
(So, Not duplicate of :) Move layouts up when soft keyboard is shown?
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //This Code brings up the keyboard at starting of the activity and pushes all Edit Text up. So not useful getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); I can add ScrollView but it seems like just workaround and doesn't seem a solution.
Feel there should be a solution programmatically like setting something InputMethodManager.