2
    // fetch window manager object 
     mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
     // set layout parameter of window manager
     WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
                30, // width of layout 30 px
                200, // height is equal to full screen
                WindowManager.LayoutParams.TYPE_PHONE, // Type Ohone, These are non-application windows providing user interaction with the phone (in particular incoming calls).
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
               // WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH // this window won't ever get key input focus  
                PixelFormat.TRANSLUCENT
                );      
     mParams.gravity = Gravity.LEFT | Gravity.TOP;   
     //mParams.setTitle("Load Average");

     LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

     mWindowManager.addView(touchLayout, mParams);

     touchLayout.setOnTouchListener(this);

这只是代码片段。我的第一个问题是在视图中接收触摸,但是,在此服务运行时触摸其他应用程序中的编辑文本框时,软键盘无法打开。我尝试了各种解决问题的标志,但我失去了将触摸事件注册到屏幕部分的能力,如代码中所示。

我没有想法,有没有人知道我哪里出错了,或者 Android 4.2.2+ 的替代解决方案?

4

1 回答 1

0

尝试这个:

Dialog dialog = new Dialog(this,android.R.style.Theme_DeviceDefault_Dialog_NoActionBar_MinWidth);
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    dialog.setContentView(new EditText(this));
    dialog.show();
于 2013-11-01T09:19:20.377 回答