首页 > 解决方案 > Android:禁用向下滑动并查看 wifi/飞行模式

问题描述

如何禁用用户可以向下滑动标题/通知栏,如下图所示。我希望我的应用程序在 kiosk 模式下运行,并且我的用户不能向下滑动或其他任何操作。

我尝试使用设置一些标志,但我得到的只是某种信息亭模式,但用户仍然可以在向下滑动时查看 wifi/飞机等屏幕。

请帮忙,我在 Stackoverflow 上找不到好的答案

我不希望我的用户看到下面的屏幕。

在此处输入图像描述

标签: android

解决方案


在此处参考此答案

或者

 private void disablePullNotificationTouch() {
            WindowManager manager = ((WindowManager) getApplicationContext()
                    .getSystemService(Context.WINDOW_SERVICE));
            WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
            localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
            localLayoutParams.gravity = Gravity.TOP;
            localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |

                    // this is to enable the notification to recieve touch events
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

                    // Draws over status bar
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

            localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            localLayoutParams.height = (int) (25 * getResources()
                    .getDisplayMetrics().scaledDensity);
            localLayoutParams.format = PixelFormat.RGBX_8888;
            customViewGroup view = new customViewGroup(this);
            manager.addView(view, localLayoutParams);
        }

//Add this class in your project
public class customViewGroup extends ViewGroup {

    public customViewGroup(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        Log.v("customViewGroup", "**********Intercepted");
        return true;
    }

推荐阅读