Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Untiy3d虚拟Android键盘的高度_Android_Keyboard - Fatal编程技术网

Untiy3d虚拟Android键盘的高度

Untiy3d虚拟Android键盘的高度,android,keyboard,Android,Keyboard,我尝试为Unity3d获取虚拟Android键盘的高度 我为Unity3d编写了android插件,并在下面的代码中尝试在函数跟踪中计算高度,但总是得到屏幕高度或0。我创建窗口和编辑字段,并在需要时显示它。我需要获取虚拟键盘的高度,以便在虚拟键盘上放置一些图像: public class KeyboardTool { private EditTextEx input; public Activity _activity; private PopupWindow wind

我尝试为Unity3d获取虚拟Android键盘的高度

我为Unity3d编写了android插件,并在下面的代码中尝试在函数跟踪中计算高度,但总是得到屏幕高度或0。我创建窗口和编辑字段,并在需要时显示它。我需要获取虚拟键盘的高度,以便在虚拟键盘上放置一些图像:

public class KeyboardTool
{

    private EditTextEx input;
    public Activity _activity;
    private PopupWindow window;
    public KeyboardTool(Activity activity)
    {
        if (activity == null)
            activity = com.unity3d.player.UnityPlayer.currentActivity;

        _activity = activity;
        _activity.runOnUiThread(new Runnable() {@SuppressLint("NewApi") public void run() 
        {

            window = new PopupWindow(_activity);
            input = new EditTextEx(_activity);

            window.setTouchable(false);
            window.setFocusable(true);
            window.setSplitTouchEnabled(false);
            window.setOutsideTouchable(true);
            window.setIgnoreCheekPress();
            window.setClippingEnabled(false);


            window.setContentView(input);
            window.setBackgroundDrawable(new ColorDrawable(0));


            input.setInputType(InputType.TYPE_CLASS_TEXT);
            input.setBackgroundColor(0);
            input.setVisibility(View.VISIBLE);
            input.setFocusable(true);
            input.setFocusableInTouchMode(true);

            window.setInputMethodMode(PopupWindow.INPUT_METHOD_FROM_FOCUSABLE);
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            UnityPlayer.currentActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);


            Trace();
        }});
    }

    @SuppressLint("NewApi") private void Trace()
    {
        Window rootWindow = UnityPlayer.currentActivity.getWindow();
        View rootView = rootWindow.getDecorView().findViewById(android.R.id.content);

        Log.i("xxx", "xxx rootView " + rootView);

        rootView.getViewTreeObserver().addOnGlobalLayoutListener
        (
                new ViewTreeObserver.OnGlobalLayoutListener() {
                public void onGlobalLayout(){
                    Rect r = new Rect();
                    View view = UnityPlayer.currentActivity.getWindow().getDecorView();
                    view.getWindowVisibleDisplayFrame(r);
                    Log.i("xxx", "xxx left " + r.left +" " + r.top+ " " +  r.right + " " + r.bottom);
                    // r.left, r.top, r.right, r.bottom

                    Window rootWindow = UnityPlayer.currentActivity.getWindow();
                    View rootView = rootWindow.getDecorView().findViewById(android.R.id.content);
                    int heightDiff = rootView.getHeight()- rootWindow.getDecorView().getHeight();
                    Log.i("", "xxx heightDiff " + heightDiff + "rootView.getHeight() " + rootView.getHeight() + " rootWindow.getDecorView().getHeight() " + rootWindow.getDecorView().getHeight());
                }
                });
    }

    public void Show()
    {
        this.canceled = false;
        this.done = false;
        if (input != null)
        {
            input.done = false;
            input.canceled = false;
        }
        _activity.runOnUiThread(new Runnable() {public void run() 
        {
            window.setFocusable(true);
            input.setFocusable(true);
            input.setFocusableInTouchMode(true);

            window.showAtLocation(_activity.getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, 0);
            input.requestFocus();
            input.bringToFront();
            InputMethodManager imm = (InputMethodManager)_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(input, 0);

            Trace();
        }});
    }

    public void Hide()
    {
        _activity.runOnUiThread(new Runnable() {public void run() 
        {
            window.setFocusable(false);
            input.setFocusable(false);
            input.setFocusableInTouchMode(false);
            input.clearFocus();
            window.dismiss();

            InputMethodManager imm = (InputMethodManager)_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(input.getWindowToken(), 0);

            Trace();
        }});
    }
}