应用禁用通知栏下拉这个需求让我头疼了好几天
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 }