当使用 Unity 在 Android 上可见触摸屏键盘时,如何调整视图大小? [英] How to resize view when touchscreen keyboard is visible on Android with Unity?

查看:19
本文介绍了当使用 Unity 在 Android 上可见触摸屏键盘时,如何调整视图大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Unity 中,我无法控制触摸屏键盘.Android 的 TouchScreenKeyboard 类只有一个参数.

In Unity I can't control the touchscreen keyboard. TouchScreenKeyboard class has only one parameters for Android.

if(TouchScreenKeyboard.visible)
{ float keyboardHeight = TouchScreenKeyboard.area.height;
  // will resize the view here! But this return zero!
}

还有其他方法可以知道 Android 上键盘的高度吗?

Is there any other way to know the height of the keyboard on Android ?

推荐答案

这应该可以解决问题 (在此处找到):

This should do the trick (found here):

    public int GetKeyboardSize()
    {
        using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            AndroidJavaObject View = UnityClass.GetStatic<AndroidJavaObject>("currentActivity").Get<AndroidJavaObject>("mUnityPlayer").Call<AndroidJavaObject>("getView");

            using(AndroidJavaObject Rct = new AndroidJavaObject("android.graphics.Rect"))
            {
                View.Call("getWindowVisibleDisplayFrame", Rct);

                return Screen.height - Rct.Call<int>("height");
            }
        }
    }

这篇关于当使用 Unity 在 Android 上可见触摸屏键盘时,如何调整视图大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆