上接收触摸的所有窗口的顶部的Andr​​oid叠加布局 [英] Android overlay layout on top of all windows that receives touches

查看:152
本文介绍了上接收触摸的所有窗口的顶部的Andr​​oid叠加布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个对所有应用程序和窗口与以下code的顶部会显示一个观点:

I have created a view that displays on top of all applications and windows with the following code:

        //These three are our main components.
    WindowManager wm;
    LinearLayout ll;
    WindowManager.LayoutParams ll_lp;

    //Just a sample layout parameters.
    wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    ll_lp = new WindowManager.LayoutParams();
    ll_lp.format = PixelFormat.TRANSLUCENT;
    ll_lp.height = WindowManager.LayoutParams.FILL_PARENT;
    ll_lp.width = WindowManager.LayoutParams.FILL_PARENT;
    ll_lp.gravity = Gravity.CLIP_HORIZONTAL | Gravity.TOP;

    //This one is necessary.
    ll_lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

    //Play around with these two.
    ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

    //This is our main layout.
    ll = new LinearLayout(this);
    ll.setBackgroundColor(android.graphics.Color.argb(50, 255, 255, 255));
    ll.setHapticFeedbackEnabled(true);
    ll.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Toast.makeText(getApplicationContext(), "TOUCHED", Toast.LENGTH_SHORT).show();
            return false;
        }
        });

    //And finally we add what we created to the screen.
    wm.addView(ll, ll_lp);

由于FLAG_NOT_TOUCHABLE设置,它只显示视图,但没有收到任何触摸事件。视图背后的应用程序接收所有触摸事件。 但是,如果我不设置这个标志,那么只有视图接收触摸导致其后面的应用程序不能接收。

Because FLAG_NOT_TOUCHABLE is set, it only displays the view but doesn't receive any touch events. The application behind the view receives all touch events. However, if i don't set the flag, then only the view receives touches causing the application behind it to not receive any.

有没有办法为视图和它背后的应用程序来接收触摸?我试图返回false,但仍然是相同的。

Is there a way for both the view and the application behind it to receive touches? I have tried returning false but still the same.

任何帮助将是很大的AP preciated!

Any help would be greatly appreciated!

推荐答案

如果我不是弄错,在后台的观点多数民众赞成在没有接收到触摸事件,因为它被过滤掉了系统prevent点击顶攻击。

If im not mistaking, the view thats in the background is not receiving touch events because its being filtered out by the system to prevent "click jacking" exploits.

您可能能够通过关闭触摸事件的过滤在后台视图使用<一个绕过这个系统功能href="http://developer.android.com/reference/android/view/View.html#setFilterTouchesWhenObscured%28boolean%29"相对=nofollow> View.setFilterTouchesWhenObscured(布尔)的方法。

You might be able to get around this system feature by turning off the filtering of touch events for the view in the background using the View.setFilterTouchesWhenObscured(Boolean) method.

这篇关于上接收触摸的所有窗口的顶部的Andr​​oid叠加布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆