2013-09-28 90 views
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 System Overlay 4.2.2

我出來的想法,有沒有人有任何想法,我哪裏會出錯,或爲Android 4.2.2 +的替代解決方案嗎?

+0

我假設你正在使用的標準Android鍵盤,而不是一個第三方的一個,對不對? – Izmaki

回答

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();