- Home /
Android keyboard pushes scene up.
Hello folks.
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!
Like I said, I have already googled the problem. All the search results say that I have to include android:windowSoftInput$$anonymous$$ode in my manifest. I added it in my main activity and in the admob activity using the values "adjustNothing", "adjustPan" and "adjustResize" separately and still get the same results.
Did you see the results that say "How to avoid soft keyboard pushing my layout"?
Like this one, that has a working accepted answer? Did you do it like they did? :)
For example, some say
android:windowSoftInput$$anonymous$$ode="adjustPan"
to manifest, while others say:
windowSoftInput$$anonymous$$ode : Ti.UI.Android.SOFT_INPUT_ADJUST_PAN
at window creation.
This is an Android issue, not a Unity one.
It simply seems that your Ad server is making changes that are not being reversed.
I am a little bit confused. The link you posted has things that cannot be used in Unity such as setting view height. Therefore I cannot apply any of the solutions to my game.
Also, the other one "How to avoid soft keyboard pushing my layout", is saying that I have to set isScrollContainer="false" which again does not apply to Unity.
Like I said, all I have are sprites and only one GUI object, the textfield, which I manually disable before the keyboard pops up. I do not have any scrollviews.
EDIT: How do I add code at window creation in Unity?
This is why I say it's an Android problem. These things probably need to be linked through the Android API. After all, it is a problem with Android built in $$anonymous$$eyboard and how it is handling the Unity Player, which is linked and utilised through the Android API.
The other things are being applied to the Android $$anonymous$$anifest which is also not a part of Unity.
I would attempt to export my Project to eclipse and adjust the Android API stuff from there.
Answer by guavaman · Aug 05, 2015 at 03:48 AM
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.
Answer by Adquizition · Aug 06, 2015 at 02:35 AM
I found a japanese blog post that does fix this with in Unity. I tried to add the line in the manifest file and it didn't seem to affect anything but this nice blog post did, http://westhillapps.blog.jp/archives/40341694.html
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
}
}
Your answer
Follow this Question
Related Questions
Inputmode on 18:9 mobile device shows navigation bar 0 Answers
problems with implementing Admob banner ads 0 Answers
deactivate script for period of time after script is used. 0 Answers
Admob interstitial ad not showing up 1 Answer
Missing AdActivity with android:configChanges in AndroidManifest.xml 0 Answers