使用WindowManager添加View覆盖掉通知栏来实现禁止下拉通知栏功能:

import android.content.Context;import android.graphics.PixelFormat;import android.view.Gravity;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.view.ViewGroup;import android.view.WindowManager;import android.widget.LinearLayout;public class DisableNotiView {    private WindowManager.LayoutParams mLayoutParam;    private Context mContext;    private WindowManager wm;    private LinearLayout relative;    public DisableNotiView(Context context) {        mContext = context;    }    public void createView(){        wm = ((WindowManager)mContext.getApplicationContext()                .getSystemService("window"));        int mScreenWidth = wm.getDefaultDisplay().getWidth();        mLayoutParam = new WindowManager.LayoutParams();        mLayoutParam.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;        mLayoutParam.format = PixelFormat.RGBA_8888;        mLayoutParam.windowAnimations = 16973828;        mLayoutParam.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |                  WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |                  WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;          mLayoutParam.gravity = Gravity.TOP;        mLayoutParam.width = mScreenWidth;        mLayoutParam.height = getStatusBarHeight(mContext);        LayoutInflater inflater = LayoutInflater.from(mContext.getApplicationContext());        relative = (LinearLayout)inflater.inflate(R.layout.state_bat_linearlayout, null, false);        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT                , getStatusBarHeight(mContext));        relative.setLayoutParams(params);        relative.setOnTouchListener(new OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                return false;            }        });        wm.addView(relative, mLayoutParam);    }    public static int getStatusBarHeight(Context context) {          int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");          return context.getResources().getDimensionPixelSize(resourceId);      }      public void removeView(){        wm.removeView(relative);    }}

更多相关文章

  1. Android沉浸式通知栏的一个开源库SystemBarTint简单使用,android
  2. Android 购物车加减功能的实现代码
  3. android 我的功能模块模板布局之一
  4. android LayoutInflater.inflate()的参数及其功能
  5. Android几个常用功能代码(校园助手开发笔记)
  6. Android 通知之 Notification
  7. Android 发送通知 notification
  8. android GPS JAVA 获取GPS功能是否禁用
  9. Android 双击返回键退出功能的实现

随机推荐

  1. Android中两个Activity之间的跳转
  2. Android(安卓)NDK的安装。(下一篇是关于 o
  3. 【Android(安卓)开发教程】在服务中执行
  4. Android(安卓)arm linux 系统调用实现
  5. Android(安卓)Bluetooth开发
  6. Android实现发送短信验证码倒计时功能示
  7. 在Ubuntu中获取Android源文件(相关整理&
  8. android多国语言列表
  9. DDMS files not found: D:\ProgramFiles
  10. android学习之模拟器SD卡的创建(tools)