Reputation: 2719
My cordova app consists of multiple html files each representing different views but keyboard is messing up the webview. On iOS I used ionic-plugin-keyboard’s
cordova.plugins.Keyboard.disableScroll(true);
to fix things but that only supports iOS. I could add
android:windowSoftInputMode="adjustPan" to AndroidManifest.xml which seems to fix it but I want this to apply to one view only. In other words, I want the keyboard to push up the views except one specific view.
I thought I could switch between these two
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
depending on what view I am in but it looks like once setSoftInputMode is set it cannot be changed later? What’s the best way of solving this? Also, how would I prevent keyboard from pushing up a footer? (this behavior only appears in Android).
Sorry if my questions are confusing but I’ve been trying to solve these for few days now and keyboard is really frustrating me.
Upvotes: 1
Views: 1155
Reputation: 2719
I think I found the best way how to solve this issue. I made a cordova plugin. When I wrote this question (30 minutes before this answer) I did not have any idea how to create a cordova plugin so I followed this great tutorial: http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/.
Based on this one I imported import android.view.WindowManager;
and than in the execute function in the runOnUiThread
runnable I added this
if(action.equals("adjustPan"))
cordova.getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
else if(action.equals("adjustResize"))
cordova.getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Than based on how I call the function from javascript, it changes the input mode :)
I will add this plugin to github and add the link here
Edit: Here is the link from the plugin https://github.com/denkomanceski/windowSoftInputMode
All the instructions are there
Upvotes: 3