When the user taps on an input field on a web page, it can trigger the native on-screen keyboard to be shown, and the keyboard may inadvertently cover the input field that was tapped. To prevent the input field from being covered, it's possible to make the webview automatically adjust when the keyboard is shown so that the input field remains above the keyboard. You can configure that with the following steps:
- First, disable "Hide navigation bar" and "Render outside safe area" in Android Player Settings -> Presentation and Resolution:
- Add the following script to an object in your scene to set the window's soft input mode:
using UnityEngine;
// From this article: https://support.vuplex.com/articles/android-prevent-keyboard-from-covering-input-field
class KeyboardSetting : MonoBehaviour {
void Awake() {
// This C# executes the following Java code:
// Activity activity = com.unity3d.player.UnityPlayer.currentActivity;
// activity.runOnUiThread(() -> {
// activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
// });
var UnityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = UnityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
var window = activity.Call<AndroidJavaObject>("getWindow");
int SOFT_INPUT_ADJUST_RESIZE = 16;
window.Call("setSoftInputMode", SOFT_INPUT_ADJUST_RESIZE);
}));
}
}