When adding view to window with WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, it is not getting touch event

后端 未结 1 1483
轻奢々
轻奢々 2021-01-03 11:00

I need to display my view on top of dialer application, so I was using TYPE_PHONE for this purpose which is touchable, but still on some devices like Nexus 5 dialer applicat

相关标签:
1条回答
  • 2021-01-03 11:45

    After lot of searching for above problem, I found solution my self. Here it is how I made view to be on top of everything inside device and also making it touchable which was not possible with TYPE_SYSTEM_OVERLAY.

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                            WindowManager.LayoutParams.MATCH_PARENT,
                            WindowManager.LayoutParams.WRAP_CONTENT,
                            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                            PixelFormat.TRANSPARENT);
    
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(view, params);
    
    0 讨论(0)
提交回复
热议问题