So this is the problem I am having:
I have a 2D scene with a sprite for background, several sprite buttons and a GUI textbox. If you touch the textbox, the keyboard opens up and everything is fine. However, once you click on the Google admob banner at the bottom of the screen, press back to exit the browser and get back to the game and then touch the textbox to get the keyboard, the keyboard appears and pushes the entire level upwards. If you close the keyboard, the level goes back to normal. This will continue happening until you close and reopen the game. This however doesn’t happen on other ads I have in the game such as Chartboost.
I have googled the problem and tried a few things I found such as adding android:windowSoftInputMode however I think this doesn’t apply to Unity builds since nothing I tried made a difference.
I have tried this on several devices with the same results. If you have any ideas how to fix this or something I can try or any more info from me just let me know. Thanks!
Same problem here. None of the suggestions about adding things to the Android manifest worked for me including several others I found on the web. The only thing that worked for me was to hide and show the banner ad after Unity receives focus again.
void OnApplicationFocus(bool focusStatus) {
// Hack to fix Google AdMob bug that makes the keyboard push the screen up after application receives focus again
// after clicking on the banner ad
#if UNITY_ANDROID
if(focusStatus && shouldShowBanner) {
HideBanner();
ShowBanner();
}
#endif
}
Obviously exact code depends on your implementation.
Their syntax is off a little so I adjusted it accordingly here:
using UnityEngine;
using System.Collections;
public class NotScreenResizeAndroid: MonoBehaviour
{
void Start ()
{
NotScreenResizeAndroidSetting ();
}
/// <Summary>
// You do not change the screen size with a soft keyboard displayed at the time of the notification bar display set in the /// Android
/// </ Summary>
void NotScreenResizeAndroidSetting ()
{
#if UNITY_ANDROID
if (Application.platform != RuntimePlatform.Android)
{
return;
}
AndroidJNI.AttachCurrentThread ();
AndroidJNI.PushLocalFrame (0);
try
{
// Get // Activity
using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic <AndroidJavaObject> ("currentActivity"))
{
// Run on the UI thread
joActivity.Call ("runOnUiThread", new AndroidJavaRunnable (RunOnUiThread));
}
}
catch (System.Exception ex)
{
Debug.LogError (ex.Message);
}
finally
{
AndroidJNI.PopLocalFrame (System.IntPtr.Zero);
}
#endif
}
/// <Summary>
/// Run on the UI thread
/// </ Summary>
void RunOnUiThread ()
{
#if UNITY_ANDROID
// Call the following code: // on the Activity of Android
// GetWindow () setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING).;
using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic <AndroidJavaObject> ("currentActivity"))
using (AndroidJavaObject joWindow = joActivity.Call <AndroidJavaObject> ("getWindow"))
{
joWindow.Call ("setSoftInputMode", 48);
}
#endif
}
}