在 Unity 中,我无法控制触摸屏键盘.TouchScreenKeyboard 类只有一个 Android 参数.
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 上可见触摸屏键盘时如何调整视图大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!