当带有Unity的Android上可见触摸屏键盘时,如何调整视图大小? [英] How to resize view when touchscreen keyboard is visible on Android with Unity?
本文介绍了当带有Unity的Android上可见触摸屏键盘时,如何调整视图大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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上可见触摸屏键盘时,如何调整视图大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文