Android开发禁用通知栏下拉

应用禁用通知栏下拉这个需求让我头疼了好几天
statusbar用了后但是效果不是很满意
其他的方法试过但是没有效果,所以就换个思路吧
做法是在通知栏区域弄一个透明的window,这样下拉的时候触摸的区域就是这个window,系统的就下拉不了了
改做法是需要在应用上方显示一个window 所以需要权限

1 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 2 3 4 public static final String STATUS_BAR_HEIGHT = "status_bar_height"; 5 public static final String DIMEN = "dimen"; 6 public static final String DEF_PACKAGE = "android"; 7 public static void preventStatusBarExpansion(Context context) { 8 WindowManager manager = ((WindowManager) context.getApplicationContext() 9 .getSystemService(Context.WINDOW_SERVICE)); 10 11 WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); 12 localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 13 localLayoutParams.gravity = Gravity.TOP; 14 localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 15 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 16 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 17 18 localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; 19 20 int resId = context.getResources() 21 .getIdentifier(STATUS_BAR_HEIGHT, DIMEN, DEF_PACKAGE); 22 int result; 23 if (resId > 0) { 24 result = context.getResources() 25 .getDimensionPixelSize(resId); 26 } else { 27 // Use Fallback size: 28 result = 60; // 60px Fallback 29 } 30 31 localLayoutParams.height = result; 32 localLayoutParams.format = PixelFormat.TRANSPARENT; 33 34 if (view == null) { 35 view = new CustomViewGroup(context); 36 } 37 38 try { 39 if (manager != null) { 40 manager.addView(view, localLayoutParams); 41 } 42 } catch (Exception ignored) { 43 } 44 } 45 46 public static void allowStatusBarExpansion(Context context) { 47 WindowManager manager = ((WindowManager) context.getApplicationContext() 48 .getSystemService(Context.WINDOW_SERVICE)); 49 try { 50 if (manager != null) { 51 manager.removeViewImmediate(view); 52 } 53 } catch (Exception ignored) { 54 } 55 } 56 57 public static class CustomViewGroup extends ViewGroup { 58 public CustomViewGroup(Context context) { 59 super(context); 60 } 61 62 @Override 63 protected void onLayout(boolean changed, 64 int l, 65 int t, 66 int r, 67 int b) { 68 } 69 70 @Override 71 public boolean onInterceptTouchEvent(MotionEvent ev) { 72 // Intercepted touch! 73 return true; 74 } 75 }
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Notification使用详解之一:基础应用

在消息通知时,我们经常用到两个组件Toast和Notification。特别是重要的和需要长时间显示的信息,用Notification就最合适不过了。当有消息通知时,状态栏会显示通知的图标和文字,通过下拉状态栏,就可以看到通知信息了,Android这一创新性的UI组件赢得了用户的一致好评,就连苹果也开始模仿了。今天我们就结合实例,探讨一下Notifica

Twitter的分布式自增ID算法snowflake (Java版)

概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移