TYPE_SYSTEM_ALERT和TYPE_SYSTEM_OVERLAY之间的切换,并捕获触摸事件不能正常工作 [英] Switching between TYPE_SYSTEM_ALERT AND TYPE_SYSTEM_OVERLAY , and capturing the touch events not working properly
问题描述
我做的服务视图,它总是在Android的每个应用程序之上运行。
I made a View in service which runs always on top of every application in android.
首先,服务的行为是TYPE_SYSTEM_ALERT。
Initially, the behaviour of service is TYPE_SYSTEM_ALERT .
WindowManager.LayoutParams layparams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
layparams .gravity = Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL;
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(serviceView, layparams );
我改变服务在运行时的行为意味着触摸TYPE_SYSTEM_ALERT和TYPE_SYSTEM_OVERLAY之间的切换。切换发生时,我接触到视图参数之外,当触摸里面的视图参数。
I am changing the behaviour of service at run time means switching between TYPE_SYSTEM_ALERT AND TYPE_SYSTEM_OVERLAY on touch. Switch take place when I touch outside the view parameters and when touch inside the view parameters.
layparams .type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
Using updateViewLayout(serviceView, layparams )
问题:是,当我接触来看之外,第一触摸刚刚启动TYPE_SYSTEM_OVERLAY之后再以外的应用程序工作正常。当TYPE_SYSTEM_OVERLAY正在工作,之后,如果将视图内触摸它会触发对象的视图不视图的动作后面的动作。但是,当u一旦触碰观点TYPE_SYSTEM_ALERT将被应用到现在的视图将正常。
PROBLEM: Is when I touch outside of view , the first touch just activate TYPE_SYSTEM_OVERLAY and after then outside app works fine. When TYPE_SYSTEM_OVERLAY is working , after that when you touch within the view it will trigger the action of object behind the view not the action of the view. But when u once touch the view TYPE_SYSTEM_ALERT will be applied and now the View will behave normally .
当前实施:我要摸两次,工作是特别的事情,当开关带布局参数之间发生
Current Implementation : I have to touch twice to work that particular thing when switch take place between layout parameters.
推荐答案
使用这样的产品......完美的作品在ICS及以上
use this one... works perfectly on ICS and above
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;//This one is necessary.
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
params.gravity = Gravity.TOP | Gravity.RIGHT;
params.x = 0;
params.y = -params.height;
windowManager.addView(tile, params);
这篇关于TYPE_SYSTEM_ALERT和TYPE_SYSTEM_OVERLAY之间的切换,并捕获触摸事件不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!