android - Android:禁用向下滑动并查看 wifi/飞行模式
问题描述
如何禁用用户可以向下滑动标题/通知栏,如下图所示。我希望我的应用程序在 kiosk 模式下运行,并且我的用户不能向下滑动或其他任何操作。
我尝试使用设置一些标志,但我得到的只是某种信息亭模式,但用户仍然可以在向下滑动时查看 wifi/飞机等屏幕。
请帮忙,我在 Stackoverflow 上找不到好的答案
我不希望我的用户看到下面的屏幕。
解决方案
在此处参考此答案
或者
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;
}
推荐阅读
- mysql - SQL 按列计数出现次数
- angular - 用 jasmine 测试 NGXS 异常
- node.js - 使用 node.js 监听特定 URL 的请求(不是 LOCALHOST)
- php - MYSQLi 创建数据库?作为名字
- android - 我怎样才能在android中保持“在线”状态
- cron - 如何使用 cronjob 删除空文件夹和子文件夹
- excel - 如何在条形图上添加数据标签并使用 VBA 从单元格中添加值
- mysql - sql查询密码列
- salesforce - Visualforce 页面弹出窗口
- typescript - 我试图装饰的类的实例中缺少 TypeScript 报告属性